effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Pervasives.Lemma | val _sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) | val _sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)]
let _sigma1_lemma #a #m x
: Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = | false | null | true | LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._sigma1",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._sigma1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)] | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val _sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] | [] | Hacl.Spec.SHA2.Equiv._sigma1_lemma | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._sigma1 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._sigma1 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._sigma1 x)] | {
"end_col": 79,
"end_line": 61,
"start_col": 2,
"start_line": 61
} |
FStar.Pervasives.Lemma | val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l | val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l = | false | null | true | reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 ( +| ) st1 st in
state_spec_v_map2_add #a #m st1 st l | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.state_spec_v_map2_add",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"Lib.Sequence.index",
"Hacl.Spec.SHA2.Vec.op_Plus_Bar",
"Lib.Sequence.map2",
"Prims.unit",
"Hacl.Spec.SHA2.Equiv.shuffle_lemma_l",
"Hacl.Spec.SHA2.Vec.shuffle",
"Hacl.Spec.SHA2.Equiv.load_ws_lemma_l",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.load_ws",
"FStar.Pervasives.reveal_opaque",
"Hacl.Spec.SHA2.Vec.update"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l]) | [] | Hacl.Spec.SHA2.Equiv.update_lemma_l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Hacl.Spec.SHA2.Vec.multiblock_spec a m ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update b st)).[ l ] ==
Hacl.Spec.SHA2.update a (( .(||) ) b l) (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | {
"end_col": 38,
"end_line": 452,
"start_col": 2,
"start_line": 444
} |
FStar.Pervasives.Lemma | val _Sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) | val _Sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)]
let _Sigma0_lemma #a #m x
: Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = | false | null | true | LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._Sigma0",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._Sigma0",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)] | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val _Sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] | [] | Hacl.Spec.SHA2.Equiv._Sigma0_lemma | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Sigma0 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._Sigma0 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._Sigma0 x)] | {
"end_col": 79,
"end_line": 43,
"start_col": 2,
"start_line": 43
} |
FStar.Pervasives.Lemma | val _Sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) | val _Sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)]
let _Sigma1_lemma #a #m x
: Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = | false | null | true | LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._Sigma1",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._Sigma1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)] | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val _Sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] | [] | Hacl.Spec.SHA2.Equiv._Sigma1_lemma | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Sigma1 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._Sigma1 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._Sigma1 x)] | {
"end_col": 79,
"end_line": 49,
"start_col": 2,
"start_line": 49
} |
FStar.Pervasives.Lemma | val _sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) | val _sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)]
let _sigma0_lemma #a #m x
: Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = | false | null | true | LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._sigma0",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._sigma0",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)] | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val _sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] | [] | Hacl.Spec.SHA2.Equiv._sigma0_lemma | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._sigma0 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._sigma0 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._sigma0 x)] | {
"end_col": 79,
"end_line": 55,
"start_col": 2,
"start_line": 55
} |
FStar.Pervasives.Lemma | val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end | val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n = | false | null | true | let ws_v, st_v = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[ l ], (state_spec_v st0).[ l ]) in
let ws, st = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0
then
(eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l)
else
let ws_v1, st_v1 = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let ws1, st1 = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.SHA2.num_rounds16",
"Hacl.Spec.SHA2.k_w",
"Spec.Hash.Definitions.words_state",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma_l",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Lib.LoopCombinators.eq_repeati0",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.shuffle_inner_loop",
"Hacl.Spec.SHA2.Vec.shuffle_inner_loop",
"Prims.bool",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Hacl.Spec.SHA2.Equiv.shuffle_loop_lemma",
"Lib.LoopCombinators.repeati",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.ws_spec_v",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) | [
"recursion"
] | Hacl.Spec.SHA2.Equiv.shuffle_loop_lemma | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ws0: Hacl.Spec.SHA2.Vec.ws_spec a m ->
st0: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= Hacl.Spec.SHA2.num_rounds16 a}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Lib.LoopCombinators.repeati n Hacl.Spec.SHA2.Vec.shuffle_inner_loop (ws0, st0) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ws_v st_v = _ in
let _ =
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.shuffle_inner_loop a)
((Hacl.Spec.SHA2.Vec.ws_spec_v ws0).[ l ], (Hacl.Spec.SHA2.Vec.state_spec_v st0).[ l ]
)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ws st = _ in
(Hacl.Spec.SHA2.Vec.ws_spec_v ws_v).[ l ] == ws /\
(Hacl.Spec.SHA2.Vec.state_spec_v st_v).[ l ] == st)
<:
Type0)
<:
Type0)) | {
"end_col": 65,
"end_line": 280,
"start_col": 46,
"start_line": 264
} |
FStar.Pervasives.Lemma | val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
} | val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i = | false | null | true | let l = lanes a m in
let i_new = (i / l) * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
calc ( == ) {
i_new % l;
( == ) { () }
((i / l) * l + j) % l;
( == ) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
( == ) { Math.Lemmas.small_mod j l }
j;
};
calc ( == ) {
(i_new / l) * l + j_new;
( == ) { () }
(((i / l) * l + j) / l) * l + i % l;
( == ) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
( == ) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
(i / l) * l + (j / l) * l + i % l;
( == ) { Math.Lemmas.euclidean_division_definition i l }
i + (j / l) * l;
( == ) { Math.Lemmas.small_div j l }
i;
} | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.division_addition_lemma",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.euclidean_division_definition",
"FStar.Math.Lemmas.small_div",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Math.Lemmas.small_mod",
"Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij",
"Hacl.Spec.SHA2.Vec.lanes_t"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) | [] | Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij_subst | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Hacl.Spec.SHA2.Vec.multiblock_spec a m ->
j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} ->
i: Prims.nat{i < 16}
-> FStar.Pervasives.Lemma
(ensures
(let l = Hacl.Spec.SHA2.Vec.lanes a m in
(Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec.load_blocks b).[ (i / l) * l + j ]).[ i % l ] ==
Lib.ByteSequence.uint_from_bytes_be (FStar.Seq.Base.slice (( .(||) ) b j)
(i * Spec.Hash.Definitions.word_length a)
(i * Spec.Hash.Definitions.word_length a + Spec.Hash.Definitions.word_length a)))) | {
"end_col": 5,
"end_line": 389,
"start_col": 44,
"start_line": 358
} |
FStar.Pervasives.Lemma | val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec update_nblocks_loop_lemma #a #m len b st l n =
let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(|l|) in
let rp = repeati n f_sc (state_spec_v st).[l] in
if n = 0 then begin
eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[l] end
else begin
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[l] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[l] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l end | val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l]))
let rec update_nblocks_loop_lemma #a #m len b st l n = | false | null | true | let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(| l |) in
let rp = repeati n f_sc (state_spec_v st).[ l ] in
if n = 0
then
(eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[ l ])
else
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[ l ] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[ l ] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[ l ] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Hash.Definitions.words_state",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.unit",
"Hacl.Spec.SHA2.Vec.update_block",
"Prims.bool",
"Hacl.Spec.SHA2.Equiv.update_block_lemma_l",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Hacl.Spec.SHA2.Vec.word",
"Prims.l_or",
"Prims.l_and",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.state_word_length",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.Equiv.update_nblocks_loop_lemma",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.SHA2.update_block",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l
val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) | [
"recursion"
] | Hacl.Spec.SHA2.Equiv.update_nblocks_loop_lemma | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= len / Spec.Hash.Definitions.block_length a}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.Vec.update_block len b)
st)).[ l ] ==
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.update_block a len (( .(||) ) b l))
(Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | {
"end_col": 54,
"end_line": 638,
"start_col": 54,
"start_line": 623
} |
FStar.Pervasives.Lemma | val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l]) | val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l = | false | null | true | let st_l:words_state a = (state_spec_v st).[ l ] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i: nat{i < 8 * word_length a}) : Lemma (lp.[ l * (8 * word_length a) + i ] == rp.[ i ]) =
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i
in
Classical.forall_intro aux;
eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[ l ]) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint8",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.word_length",
"Lib.Sequence.sub",
"Hacl.Spec.SHA2.Vec.store_state",
"Hacl.Spec.SHA2.store_state",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.eq2",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Prims.op_Addition",
"Prims.op_Multiply",
"Prims.l_True",
"Prims.squash",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.index",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Hacl.Spec.SHA2.Equiv.store_state_lemma_ij",
"Lib.ByteSequence.index_uints_to_bytes_be",
"Spec.Hash.Definitions.word_t",
"Lib.Sequence.lseq",
"Spec.Hash.Definitions.words_state"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l]) | [] | Hacl.Spec.SHA2.Equiv.store_state_lemma_l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
Lib.Sequence.sub (Hacl.Spec.SHA2.Vec.store_state st)
(l * (8 * Spec.Hash.Definitions.word_length a))
(8 * Spec.Hash.Definitions.word_length a) ==
Hacl.Spec.SHA2.store_state a (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | {
"end_col": 46,
"end_line": 570,
"start_col": 36,
"start_line": 557
} |
FStar.Pervasives.Lemma | val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end | val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n = | false | null | true | let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[ l ] in
if n = 0
then
(eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[ l ];
ws_next_inner_lemma_l 0 ws l)
else
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[ l ] in
ws_next_lemma_loop #a #m ws l (n - 1);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[ l ] (n - 1);
ws_next_inner_lemma_l (n - 1) lp0 l;
() | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.SHA2.Equiv.ws_next_inner_lemma_l",
"Prims.unit",
"Lib.LoopCombinators.eq_repeati0",
"Hacl.Spec.SHA2.k_w",
"Hacl.Spec.SHA2.ws_next_inner",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.ws_spec_v",
"Hacl.Spec.SHA2.Vec.ws_next_inner",
"Prims.bool",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Hacl.Spec.SHA2.Equiv.ws_next_lemma_loop",
"Lib.LoopCombinators.repeati"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) | [
"recursion"
] | Hacl.Spec.SHA2.Equiv.ws_next_lemma_loop | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= 16}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.ws_spec_v (Lib.LoopCombinators.repeati n
Hacl.Spec.SHA2.Vec.ws_next_inner
ws)).[ l ] ==
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.ws_next_inner a)
(Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]) | {
"end_col": 10,
"end_line": 173,
"start_col": 41,
"start_line": 155
} |
FStar.Pervasives.Lemma | val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l = | false | null | true | eq_intro (state_spec_v (map2 ( +| ) st1 st2)).[ l ]
(map2 #_ #_ #_ #8 ( +. ) (state_spec_v st1).[ l ] (state_spec_v st2).[ l ]) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Hacl.Spec.SHA2.Vec.word",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Lib.Sequence.map2",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Plus_Bar",
"Lib.IntTypes.op_Plus_Dot",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Prims.unit"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | [] | Hacl.Spec.SHA2.Equiv.state_spec_v_map2_add | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
st1: Hacl.Spec.SHA2.Vec.state_spec a m ->
st2: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Lib.Sequence.map2 Hacl.Spec.SHA2.Vec.op_Plus_Bar st1 st2)).[
l ] ==
Lib.Sequence.map2 Lib.IntTypes.op_Plus_Dot
(Hacl.Spec.SHA2.Vec.state_spec_v st1).[ l ]
(Hacl.Spec.SHA2.Vec.state_spec_v st2).[ l ]) | {
"end_col": 73,
"end_line": 431,
"start_col": 2,
"start_line": 429
} |
FStar.Pervasives.Lemma | val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l | val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l = | false | null | true | let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[ j ] in
shuffle_core_spec_lemma_l k_t ws_t st l | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.num_rounds16",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.shuffle_core_spec_lemma_l",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.op_String_Access",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.k0",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.unit"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) | [] | Hacl.Spec.SHA2.Equiv.shuffle_inner_lemma_l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
i: Prims.nat{i < Hacl.Spec.SHA2.num_rounds16 a} ->
j: Prims.nat{j < 16} ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.shuffle_inner ws i j st)).[ l ] ==
Hacl.Spec.SHA2.shuffle_inner a
(Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]
i
j
(Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | {
"end_col": 41,
"end_line": 201,
"start_col": 45,
"start_line": 198
} |
FStar.Pervasives.Lemma | val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] | val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = | false | null | true | eq_intro #(word a)
#(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[ l ]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[ l ] (state_spec_v st).[ l ]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[ l ] (state_spec_v st).[ l ] | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8_lemma",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.unit",
"Lib.Sequence.eq_intro",
"Spec.Hash.Definitions.state_word_length",
"Hacl.Spec.SHA2.Vec.shuffle_core_spec",
"Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) | [] | Hacl.Spec.SHA2.Equiv.shuffle_core_spec_lemma_l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k_t: Hacl.Spec.SHA2.Vec.word a ->
ws_t: Hacl.Spec.SHA2.Vec.element_t a m ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.shuffle_core_spec k_t ws_t st)).[ l ] ==
Hacl.Spec.SHA2.shuffle_core_pre a
k_t
(Lib.IntVector.vec_v ws_t).[ l ]
(Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | {
"end_col": 77,
"end_line": 127,
"start_col": 2,
"start_line": 124
} |
FStar.Pervasives.Lemma | val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end | val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = | false | null | true | let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[ l ] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[ l ] in
if n = 0
then
(eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[ l ];
shuffle_inner_lemma_l #a #m ws0 i n st0 l)
else
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[ l ] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[ l ] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[ l ] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.num_rounds16",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.SHA2.Equiv.shuffle_inner_lemma_l",
"Prims.unit",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Hash.Definitions.words_state",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Hacl.Spec.SHA2.Vec.shuffle_inner",
"Prims.bool",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Hacl.Spec.SHA2.Vec.word",
"Prims.l_or",
"Prims.l_and",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.state_word_length",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.SHA2.shuffle_inner",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.ws_spec_v"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) | [
"recursion"
] | Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Prims.nat{i < Hacl.Spec.SHA2.num_rounds16 a} ->
ws0: Hacl.Spec.SHA2.Vec.ws_spec a m ->
st0: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= 16}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.Vec.shuffle_inner ws0 i)
st0)).[ l ] ==
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.shuffle_inner a (Hacl.Spec.SHA2.Vec.ws_spec_v ws0).[ l ] i)
(Hacl.Spec.SHA2.Vec.state_spec_v st0).[ l ]) | {
"end_col": 55,
"end_line": 232,
"start_col": 54,
"start_line": 216
} |
FStar.Pervasives.Lemma | val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec | val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l = | false | null | true | reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.len_length",
"Prims.nat",
"Prims.l_or",
"Prims.eq2",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_disEquality",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThan",
"FStar.Pervasives.allow_inversion",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.load_last"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) | [] | Hacl.Spec.SHA2.Equiv.load_last_lemma_l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
totlen_seq: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.len_length a) ->
fin:
Prims.nat
{ fin == Spec.Hash.Definitions.block_length a \/
fin == 2 * Spec.Hash.Definitions.block_length a } ->
len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.SHA2.Vec.load_last totlen_seq fin len b in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b0_v b1_v = _ in
let _ = Hacl.Spec.SHA2.load_last a totlen_seq fin len (( .(||) ) b l) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b0 b1 = _ in
( .(||) ) b0_v l == b0 /\ ( .(||) ) b1_v l == b1)
<:
Type0)
<:
Type0)) | {
"end_col": 24,
"end_line": 471,
"start_col": 2,
"start_line": 469
} |
FStar.Pervasives.Lemma | val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a))) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize))) | val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i = | false | null | true | let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(| idx_i |) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
assert (vec_v ((load_blocks b).[ i ]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[ i ])).[ j ] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc ( == ) {
idx_j * blocksize_l + j * blocksize;
( == ) { (Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize) }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(| idx_i |)
(idx_j * blocksize_l)
(idx_j * blocksize_l + blocksize_l)
(j * blocksize)
(j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[ i ])).[ j ] ==
BSeq.uint_from_bytes_be (Seq.slice b.(| idx_i |)
((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize))) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims._assert",
"Prims.eq2",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.load_blocks",
"Lib.ByteSequence.uint_from_bytes_be",
"FStar.Seq.Base.slice",
"Lib.IntTypes.uint8",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Prims.unit",
"FStar.Seq.Properties.slice_slice",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.paren_mul_right",
"Prims.squash",
"Lib.ByteSequence.index_uints_from_bytes_be",
"Lib.Sequence.lseq",
"Lib.ByteSequence.uints_from_bytes_be",
"FStar.Seq.Base.seq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Spec.Hash.Definitions.word_length",
"Prims.op_Division",
"Prims.op_Modulus",
"Hacl.Spec.SHA2.Vec.lanes_t"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a))) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a))) | [] | Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
b: Hacl.Spec.SHA2.Vec.multiblock_spec a m ->
j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} ->
i: Prims.nat{i < 16}
-> FStar.Pervasives.Lemma
(ensures
(let l = Hacl.Spec.SHA2.Vec.lanes a m in
let ind = ((i / l) * l + j) * Spec.Hash.Definitions.word_length a in
(Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec.load_blocks b).[ i ]).[ j ] ==
Lib.ByteSequence.uint_from_bytes_be (FStar.Seq.Base.slice (( .(||) ) b (i % l))
ind
(ind + Spec.Hash.Definitions.word_length a)))) | {
"end_col": 51,
"end_line": 344,
"start_col": 38,
"start_line": 315
} |
FStar.Pervasives.Lemma | val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
} | val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i = | false | null | true | let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc ( == ) {
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
( == ) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i)
(word_length a)
(lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
( == ) { (Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j)) }
(8 * j + i / word_length a) % lanes a m;
};
calc ( == ) {
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
( == ) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i)
(word_length a)
(lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
( == ) { (Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j)) }
(8 * j + i / word_length a) / lanes a m;
};
calc ( == ) {
Seq.index (store_state st) j_v;
( == ) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[ j_v / blocksize_v ])).[ j_v % blocksize_v ];
( == ) { BSeq.index_uints_to_bytes_be (vec_v st1.[ j_v / blocksize_v ]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[ j_v / blocksize_v ])
(j_v % blocksize_v / word_length a))).[ (j_v % blocksize_v) % word_length a ];
( == ) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[ j_v / blocksize_v ])
(j_v % blocksize_v / word_length a))).[ j_v % word_length a ];
( == ) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[ j ] (i / word_length a))).[ j_v %
word_length a ];
( == ) { (Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8)) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[ j ] (i / word_length a))).[ i %
word_length a ];
} | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.word_length",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint8",
"Prims.eq2",
"FStar.Seq.Base.index",
"Hacl.Spec.SHA2.Vec.store_state",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.numbytes",
"Spec.Hash.Definitions.word_t",
"Lib.ByteSequence.uint_to_bytes_be",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.ByteSequence.uints_to_bytes_be",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.IntVector.Serialize.index_vecs_to_bytes_be",
"Prims.squash",
"Lib.ByteSequence.index_uints_to_bytes_be",
"FStar.Math.Lemmas.modulo_modulo_lemma",
"Hacl.Spec.SHA2.Lemmas.transpose_state_lemma_ij",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Math.Lemmas.paren_mul_right",
"Prims.int",
"Prims.op_Addition",
"FStar.Math.Lemmas.division_multiplication_lemma",
"FStar.Math.Lemmas.division_addition_lemma",
"FStar.Math.Lemmas.modulo_division_lemma",
"Hacl.Spec.SHA2.Vec.transpose_state"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) | [] | Hacl.Spec.SHA2.Equiv.store_state_lemma_ij | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} ->
i: Prims.nat{i < 8 * Spec.Hash.Definitions.word_length a}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.store_state st).[ j * (8 * Spec.Hash.Definitions.word_length a) + i ] ==
(Lib.ByteSequence.uint_to_bytes_be (FStar.Seq.Base.index (Hacl.Spec.SHA2.Vec.state_spec_v st).[
j ]
(i / Spec.Hash.Definitions.word_length a))).[ i % Spec.Hash.Definitions.word_length a
]) | {
"end_col": 5,
"end_line": 545,
"start_col": 39,
"start_line": 507
} |
FStar.Pervasives.Lemma | val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l]) | val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l = | false | null | true | eq_intro #(word a)
#16
(ws_spec_v (ws_next_inner i ws)).[ l ]
(Spec.ws_next_inner a i (ws_spec_v ws).[ l ]) | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Hacl.Spec.SHA2.Vec.word",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.ws_spec_v",
"Hacl.Spec.SHA2.Vec.ws_next_inner",
"Hacl.Spec.SHA2.ws_next_inner",
"Prims.unit"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) | [] | Hacl.Spec.SHA2.Equiv.ws_next_inner_lemma_l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
i: Prims.nat{i < 16} ->
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.ws_spec_v (Hacl.Spec.SHA2.Vec.ws_next_inner i ws)).[ l ] ==
Hacl.Spec.SHA2.ws_next_inner a i (Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]) | {
"end_col": 47,
"end_line": 142,
"start_col": 2,
"start_line": 140
} |
FStar.Pervasives.Lemma | val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp | val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j = | false | null | true | let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(| j |) in
let aux (i: nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(| j |) i;
assert (Seq.index rp i ==
BSeq.uint_from_bytes_be (Seq.slice b.(| j |)
(i * word_length a)
(i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i
in
Classical.forall_intro aux;
eq_intro lp rp | {
"checked_file": "Hacl.Spec.SHA2.Equiv.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.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.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Hacl.Spec.SHA2.Vec.word",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.eq2",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.index",
"Prims.l_True",
"Prims.squash",
"Lib.IntTypes.int_t",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij_subst",
"Hacl.Spec.SHA2.Lemmas.transpose_ws_lemma_ij",
"Hacl.Spec.SHA2.Vec.load_blocks",
"Prims._assert",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.ws_spec_v",
"Hacl.Spec.SHA2.Vec.transpose_ws",
"Lib.ByteSequence.uint_from_bytes_be",
"FStar.Seq.Base.slice",
"Lib.IntTypes.uint8",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.word_length",
"Prims.op_Addition",
"Lib.ByteSequence.index_uints_from_bytes_be",
"Hacl.Spec.SHA2.Vec.lanes_t",
"Lib.ByteSequence.uints_from_bytes_be",
"Hacl.Spec.SHA2.Vec.load_ws"
] | [] | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) | false | false | Hacl.Spec.SHA2.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|)) | [] | Hacl.Spec.SHA2.Equiv.load_ws_lemma_l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.ws_spec_v (Hacl.Spec.SHA2.Vec.load_ws b)).[ j ] ==
Lib.ByteSequence.uints_from_bytes_be (( .(||) ) b j)) | {
"end_col": 16,
"end_line": 415,
"start_col": 31,
"start_line": 400
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size_key = 32 | let size_key = | false | null | false | 32 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100" | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size_key : Prims.int | [] | Spec.Salsa20.size_key | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.int | {
"end_col": 17,
"end_line": 13,
"start_col": 15,
"start_line": 13
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size_block = 64 | let size_block = | false | null | false | 64 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size_block : Prims.int | [] | Spec.Salsa20.size_block | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.int | {
"end_col": 19,
"end_line": 14,
"start_col": 17,
"start_line": 14
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let op_At f g = fun x -> g (f x) | let op_At f g = | false | null | false | fun x -> g (f x) | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_At : f: (_: _ -> _) -> g: (_: _ -> _) -> x: _ -> _ | [] | Spec.Salsa20.op_At | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | f: (_: _ -> _) -> g: (_: _ -> _) -> x: _ -> _ | {
"end_col": 32,
"end_line": 29,
"start_col": 16,
"start_line": 29
} |
|
Prims.Tot | val rounds:shuffle | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rounds : shuffle =
repeat 10 double_round | val rounds:shuffle
let rounds:shuffle = | false | null | false | repeat 10 double_round | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Lib.LoopCombinators.repeat",
"Spec.Salsa20.state",
"Spec.Salsa20.double_round"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rounds:shuffle | [] | Spec.Salsa20.rounds | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Spec.Salsa20.shuffle | {
"end_col": 24,
"end_line": 58,
"start_col": 2,
"start_line": 58
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size_nonce = 8 | let size_nonce = | false | null | false | 8 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size_nonce : Prims.int | [] | Spec.Salsa20.size_nonce | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.int | {
"end_col": 18,
"end_line": 15,
"start_col": 17,
"start_line": 15
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size_xnonce = 16 | let size_xnonce = | false | null | false | 16 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size_xnonce : Prims.int | [] | Spec.Salsa20.size_xnonce | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.int | {
"end_col": 20,
"end_line": 16,
"start_col": 18,
"start_line": 16
} |
|
Prims.Tot | val double_round:shuffle | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let double_round: shuffle =
column_round @ row_round | val double_round:shuffle
let double_round:shuffle = | false | null | false | column_round @ row_round | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.op_At",
"Spec.Salsa20.state",
"Spec.Salsa20.column_round",
"Spec.Salsa20.row_round"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14 | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val double_round:shuffle | [] | Spec.Salsa20.double_round | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Spec.Salsa20.shuffle | {
"end_col": 26,
"end_line": 55,
"start_col": 2,
"start_line": 55
} |
Prims.Tot | val salsa20_encrypt_block (st0: state) (incr: counter) (b: block) : Tot block | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_encrypt_block (st0:state) (incr:counter) (b:block) : Tot block =
let k = salsa20_core incr st0 in
xor_block k b | val salsa20_encrypt_block (st0: state) (incr: counter) (b: block) : Tot block
let salsa20_encrypt_block (st0: state) (incr: counter) (b: block) : Tot block = | false | null | false | let k = salsa20_core incr st0 in
xor_block k b | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.state",
"Spec.Salsa20.counter",
"Spec.Salsa20.block",
"Spec.Salsa20.xor_block",
"Spec.Salsa20.salsa20_core"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res
let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st'
let salsa20_key_block0 (k:key) (n:nonce) : Tot block =
let st = salsa20_init k n 0 in
salsa20_key_block st
let xor_block (k:state) (b:block) : block =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
uints_to_bytes_le ob | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_encrypt_block (st0: state) (incr: counter) (b: block) : Tot block | [] | Spec.Salsa20.salsa20_encrypt_block | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st0: Spec.Salsa20.state -> incr: Spec.Salsa20.counter -> b: Spec.Salsa20.block -> Spec.Salsa20.block | {
"end_col": 15,
"end_line": 140,
"start_col": 76,
"start_line": 138
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let constant1 = u32 0x3320646e | let constant1 = | false | null | false | u32 0x3320646e | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Lib.IntTypes.u32"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865 | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val constant1 : u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x3320646e} | [] | Spec.Salsa20.constant1 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x3320646e} | {
"end_col": 30,
"end_line": 73,
"start_col": 16,
"start_line": 73
} |
|
Prims.Tot | val salsa20_core (ctr: counter) (s: state) : Tot state | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr | val salsa20_core (ctr: counter) (s: state) : Tot state
let salsa20_core (ctr: counter) (s: state) : Tot state = | false | null | false | let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 ( +. ) s' s in
salsa20_add_counter s' ctr | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.counter",
"Spec.Salsa20.state",
"Spec.Salsa20.salsa20_add_counter",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.IntTypes.add_mod",
"Lib.Sequence.map2",
"Lib.IntTypes.uint32",
"Lib.IntTypes.op_Plus_Dot",
"Spec.Salsa20.rounds"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_core (ctr: counter) (s: state) : Tot state | [] | Spec.Salsa20.salsa20_core | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ctr: Spec.Salsa20.counter -> s: Spec.Salsa20.state -> Spec.Salsa20.state | {
"end_col": 28,
"end_line": 67,
"start_col": 54,
"start_line": 63
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let constant2 = u32 0x79622d32 | let constant2 = | false | null | false | u32 0x79622d32 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Lib.IntTypes.u32"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val constant2 : u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x79622d32} | [] | Spec.Salsa20.constant2 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x79622d32} | {
"end_col": 30,
"end_line": 75,
"start_col": 16,
"start_line": 75
} |
|
Prims.Tot | val salsa20_init (k: key) (n: nonce) (ctr0: counter) : Tot state | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st | val salsa20_init (k: key) (n: nonce) (ctr0: counter) : Tot state
let salsa20_init (k: key) (n: nonce) (ctr0: counter) : Tot state = | false | null | false | let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.nonce",
"Spec.Salsa20.counter",
"Spec.Salsa20.state",
"Spec.Salsa20.setup",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint32",
"Lib.IntTypes.u32"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_init (k: key) (n: nonce) (ctr0: counter) : Tot state | [] | Spec.Salsa20.salsa20_init | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Spec.Salsa20.key -> n: Spec.Salsa20.nonce -> ctr0: Spec.Salsa20.counter -> Spec.Salsa20.state | {
"end_col": 4,
"end_line": 97,
"start_col": 63,
"start_line": 94
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let constant0 = u32 0x61707865 | let constant0 = | false | null | false | u32 0x61707865 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Lib.IntTypes.u32"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *) | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val constant0 : u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x61707865} | [] | Spec.Salsa20.constant0 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x61707865} | {
"end_col": 30,
"end_line": 71,
"start_col": 16,
"start_line": 71
} |
|
Prims.Tot | val salsa20_key_block0 (k: key) (n: nonce) : Tot block | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_key_block0 (k:key) (n:nonce) : Tot block =
let st = salsa20_init k n 0 in
salsa20_key_block st | val salsa20_key_block0 (k: key) (n: nonce) : Tot block
let salsa20_key_block0 (k: key) (n: nonce) : Tot block = | false | null | false | let st = salsa20_init k n 0 in
salsa20_key_block st | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.nonce",
"Spec.Salsa20.salsa20_key_block",
"Spec.Salsa20.state",
"Spec.Salsa20.salsa20_init",
"Spec.Salsa20.block"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res
let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st' | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_key_block0 (k: key) (n: nonce) : Tot block | [] | Spec.Salsa20.salsa20_key_block0 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Spec.Salsa20.key -> n: Spec.Salsa20.nonce -> Spec.Salsa20.block | {
"end_col": 22,
"end_line": 131,
"start_col": 54,
"start_line": 129
} |
Prims.Tot | val xor_block (k: state) (b: block) : block | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let xor_block (k:state) (b:block) : block =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
uints_to_bytes_le ob | val xor_block (k: state) (b: block) : block
let xor_block (k: state) (b: block) : block = | false | null | false | let ib = uints_from_bytes_le b in
let ob = map2 ( ^. ) ib k in
uints_to_bytes_le ob | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.state",
"Spec.Salsa20.block",
"Lib.ByteSequence.uints_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.IntTypes.logxor",
"Lib.Sequence.map2",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.uint32",
"Lib.IntTypes.op_Hat_Dot",
"Lib.ByteSequence.uints_from_bytes_le"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res
let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st'
let salsa20_key_block0 (k:key) (n:nonce) : Tot block =
let st = salsa20_init k n 0 in
salsa20_key_block st | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val xor_block (k: state) (b: block) : block | [] | Spec.Salsa20.xor_block | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Spec.Salsa20.state -> b: Spec.Salsa20.block -> Spec.Salsa20.block | {
"end_col": 22,
"end_line": 136,
"start_col": 44,
"start_line": 133
} |
Prims.Tot | val row_round:shuffle | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14 | val row_round:shuffle
let row_round:shuffle = | false | null | false | quarter_round 0 1 2 3 @ quarter_round 5 6 7 4 @ quarter_round 10 11 8 9 @ quarter_round 15 12 13 14 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.op_At",
"Spec.Salsa20.state",
"Spec.Salsa20.quarter_round"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11 | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val row_round:shuffle | [] | Spec.Salsa20.row_round | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Spec.Salsa20.shuffle | {
"end_col": 27,
"end_line": 52,
"start_col": 2,
"start_line": 49
} |
Prims.Tot | val hsalsa20_init (k: key) (n: xnonce) : Tot state | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st | val hsalsa20_init (k: key) (n: xnonce) : Tot state
let hsalsa20_init (k: key) (n: xnonce) : Tot state = | false | null | false | let st = create 16 (u32 0) in
let st = xsetup k n st in
st | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.xnonce",
"Spec.Salsa20.state",
"Spec.Salsa20.xsetup",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.IntTypes.uint32",
"Lib.IntTypes.u32"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hsalsa20_init (k: key) (n: xnonce) : Tot state | [] | Spec.Salsa20.hsalsa20_init | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Spec.Salsa20.key -> n: Spec.Salsa20.xnonce -> Spec.Salsa20.state | {
"end_col": 4,
"end_line": 114,
"start_col": 50,
"start_line": 111
} |
Prims.Tot | val salsa20_add_counter (s: state) (ctr: counter) : Tot state | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr) | val salsa20_add_counter (s: state) (ctr: counter) : Tot state
let salsa20_add_counter (s: state) (ctr: counter) : Tot state = | false | null | false | s.[ 8 ] <- s.[ 8 ] +. (u32 ctr) | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.state",
"Spec.Salsa20.counter",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.uint32",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.u32"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_add_counter (s: state) (ctr: counter) : Tot state | [] | Spec.Salsa20.salsa20_add_counter | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Spec.Salsa20.state -> ctr: Spec.Salsa20.counter -> Spec.Salsa20.state | {
"end_col": 29,
"end_line": 61,
"start_col": 2,
"start_line": 61
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let constant3 = u32 0x6b206574 | let constant3 = | false | null | false | u32 0x6b206574 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Lib.IntTypes.u32"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32 | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val constant3 : u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x6b206574} | [] | Spec.Salsa20.constant3 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | u19: Lib.IntTypes.uint32{Lib.IntTypes.v u19 == 0x6b206574} | {
"end_col": 30,
"end_line": 77,
"start_col": 16,
"start_line": 77
} |
|
Prims.Tot | val line (a b d: idx) (s: rotval U32) (m: state) : state | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m | val line (a b d: idx) (s: rotval U32) (m: state) : state
let line (a b d: idx) (s: rotval U32) (m: state) : state = | false | null | false | let m = m.[ a ] <- (m.[ a ] ^. ((m.[ b ] +. m.[ d ]) <<<. s)) in
m | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.idx",
"Lib.IntTypes.rotval",
"Lib.IntTypes.U32",
"Spec.Salsa20.state",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.IntTypes.logxor",
"Lib.Sequence.index",
"Lib.IntTypes.rotate_left",
"Lib.IntTypes.add_mod",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.uint32",
"Lib.IntTypes.op_Hat_Dot",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.op_Less_Less_Less_Dot",
"Lib.IntTypes.op_Plus_Dot"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val line (a b d: idx) (s: rotval U32) (m: state) : state | [] | Spec.Salsa20.line | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Salsa20.idx ->
b: Spec.Salsa20.idx ->
d: Spec.Salsa20.idx ->
s: Lib.IntTypes.rotval Lib.IntTypes.U32 ->
m: Spec.Salsa20.state
-> Spec.Salsa20.state | {
"end_col": 3,
"end_line": 34,
"start_col": 67,
"start_line": 32
} |
Prims.Tot | val column_round:shuffle | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11 | val column_round:shuffle
let column_round:shuffle = | false | null | false | quarter_round 0 4 8 12 @ quarter_round 5 9 13 1 @ quarter_round 10 14 2 6 @ quarter_round 15 3 7 11 | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.op_At",
"Spec.Salsa20.state",
"Spec.Salsa20.quarter_round"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18) | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val column_round:shuffle | [] | Spec.Salsa20.column_round | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Spec.Salsa20.shuffle | {
"end_col": 25,
"end_line": 46,
"start_col": 2,
"start_line": 43
} |
Prims.Tot | val salsa20_encrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_encrypt_bytes key nonce ctr0 msg =
let st0 = salsa20_init key nonce ctr0 in
salsa20_update st0 msg | val salsa20_encrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg}
let salsa20_encrypt_bytes key nonce ctr0 msg = | false | null | false | let st0 = salsa20_init key nonce ctr0 in
salsa20_update st0 msg | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.nonce",
"Spec.Salsa20.counter",
"Lib.ByteSequence.bytes",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Salsa20.size_block",
"Lib.IntTypes.max_size_t",
"Spec.Salsa20.salsa20_update",
"Spec.Salsa20.state",
"Spec.Salsa20.salsa20_init",
"Prims.eq2",
"Prims.nat"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res
let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st'
let salsa20_key_block0 (k:key) (n:nonce) : Tot block =
let st = salsa20_init k n 0 in
salsa20_key_block st
let xor_block (k:state) (b:block) : block =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
uints_to_bytes_le ob
let salsa20_encrypt_block (st0:state) (incr:counter) (b:block) : Tot block =
let k = salsa20_core incr st0 in
xor_block k b
let salsa20_encrypt_last (st0:state) (incr:counter)
(len:size_nat{len < size_block})
(b:lbytes len) : lbytes len =
let plain = create size_block (u8 0) in
let plain = update_sub plain 0 (length b) b in
let cipher = salsa20_encrypt_block st0 incr plain in
sub cipher 0 len
val salsa20_update:
ctx: state
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg}
let salsa20_update ctx msg =
let cipher = msg in
map_blocks size_block cipher
(salsa20_encrypt_block ctx)
(salsa20_encrypt_last ctx)
val salsa20_encrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg} | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_encrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg} | [] | Spec.Salsa20.salsa20_encrypt_bytes | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Spec.Salsa20.key ->
n: Spec.Salsa20.nonce ->
c: Spec.Salsa20.counter ->
msg:
Lib.ByteSequence.bytes
{Lib.Sequence.length msg / Spec.Salsa20.size_block <= Lib.IntTypes.max_size_t}
-> cipher: Lib.ByteSequence.bytes{Lib.Sequence.length cipher == Lib.Sequence.length msg} | {
"end_col": 24,
"end_line": 171,
"start_col": 46,
"start_line": 169
} |
Prims.Tot | val salsa20_key_block (st: state) : Tot block | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st' | val salsa20_key_block (st: state) : Tot block
let salsa20_key_block (st: state) : Tot block = | false | null | false | let st' = salsa20_core 0 st in
uints_to_bytes_le st' | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.state",
"Lib.ByteSequence.uints_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Spec.Salsa20.salsa20_core",
"Spec.Salsa20.block"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_key_block (st: state) : Tot block | [] | Spec.Salsa20.salsa20_key_block | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Spec.Salsa20.state -> Spec.Salsa20.block | {
"end_col": 23,
"end_line": 127,
"start_col": 46,
"start_line": 125
} |
Prims.Tot | val salsa20_decrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> cipher: bytes{length cipher / size_block <= max_size_t}
-> msg: bytes{length cipher == length msg} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_decrypt_bytes key nonce ctr0 cipher =
let st0 = salsa20_init key nonce ctr0 in
salsa20_update st0 cipher | val salsa20_decrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> cipher: bytes{length cipher / size_block <= max_size_t}
-> msg: bytes{length cipher == length msg}
let salsa20_decrypt_bytes key nonce ctr0 cipher = | false | null | false | let st0 = salsa20_init key nonce ctr0 in
salsa20_update st0 cipher | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.nonce",
"Spec.Salsa20.counter",
"Lib.ByteSequence.bytes",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Salsa20.size_block",
"Lib.IntTypes.max_size_t",
"Spec.Salsa20.salsa20_update",
"Spec.Salsa20.state",
"Spec.Salsa20.salsa20_init",
"Prims.eq2",
"Prims.nat"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res
let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st'
let salsa20_key_block0 (k:key) (n:nonce) : Tot block =
let st = salsa20_init k n 0 in
salsa20_key_block st
let xor_block (k:state) (b:block) : block =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
uints_to_bytes_le ob
let salsa20_encrypt_block (st0:state) (incr:counter) (b:block) : Tot block =
let k = salsa20_core incr st0 in
xor_block k b
let salsa20_encrypt_last (st0:state) (incr:counter)
(len:size_nat{len < size_block})
(b:lbytes len) : lbytes len =
let plain = create size_block (u8 0) in
let plain = update_sub plain 0 (length b) b in
let cipher = salsa20_encrypt_block st0 incr plain in
sub cipher 0 len
val salsa20_update:
ctx: state
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg}
let salsa20_update ctx msg =
let cipher = msg in
map_blocks size_block cipher
(salsa20_encrypt_block ctx)
(salsa20_encrypt_last ctx)
val salsa20_encrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg}
let salsa20_encrypt_bytes key nonce ctr0 msg =
let st0 = salsa20_init key nonce ctr0 in
salsa20_update st0 msg
val salsa20_decrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> cipher: bytes{length cipher / size_block <= max_size_t}
-> msg: bytes{length cipher == length msg} | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_decrypt_bytes:
k: key
-> n: nonce
-> c: counter
-> cipher: bytes{length cipher / size_block <= max_size_t}
-> msg: bytes{length cipher == length msg} | [] | Spec.Salsa20.salsa20_decrypt_bytes | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Spec.Salsa20.key ->
n: Spec.Salsa20.nonce ->
c: Spec.Salsa20.counter ->
cipher:
Lib.ByteSequence.bytes
{Lib.Sequence.length cipher / Spec.Salsa20.size_block <= Lib.IntTypes.max_size_t}
-> msg: Lib.ByteSequence.bytes{Lib.Sequence.length cipher == Lib.Sequence.length msg} | {
"end_col": 27,
"end_line": 183,
"start_col": 49,
"start_line": 181
} |
Prims.Tot | val salsa20_encrypt_last
(st0: state)
(incr: counter)
(len: size_nat{len < size_block})
(b: lbytes len)
: lbytes len | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_encrypt_last (st0:state) (incr:counter)
(len:size_nat{len < size_block})
(b:lbytes len) : lbytes len =
let plain = create size_block (u8 0) in
let plain = update_sub plain 0 (length b) b in
let cipher = salsa20_encrypt_block st0 incr plain in
sub cipher 0 len | val salsa20_encrypt_last
(st0: state)
(incr: counter)
(len: size_nat{len < size_block})
(b: lbytes len)
: lbytes len
let salsa20_encrypt_last
(st0: state)
(incr: counter)
(len: size_nat{len < size_block})
(b: lbytes len)
: lbytes len = | false | null | false | let plain = create size_block (u8 0) in
let plain = update_sub plain 0 (length b) b in
let cipher = salsa20_encrypt_block st0 incr plain in
sub cipher 0 len | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.state",
"Spec.Salsa20.counter",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Spec.Salsa20.size_block",
"Lib.ByteSequence.lbytes",
"Lib.Sequence.sub",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Salsa20.block",
"Spec.Salsa20.salsa20_encrypt_block",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.length",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_imp",
"Lib.Sequence.create",
"Lib.IntTypes.u8"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res
let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st'
let salsa20_key_block0 (k:key) (n:nonce) : Tot block =
let st = salsa20_init k n 0 in
salsa20_key_block st
let xor_block (k:state) (b:block) : block =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
uints_to_bytes_le ob
let salsa20_encrypt_block (st0:state) (incr:counter) (b:block) : Tot block =
let k = salsa20_core incr st0 in
xor_block k b
let salsa20_encrypt_last (st0:state) (incr:counter) | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_encrypt_last
(st0: state)
(incr: counter)
(len: size_nat{len < size_block})
(b: lbytes len)
: lbytes len | [] | Spec.Salsa20.salsa20_encrypt_last | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
st0: Spec.Salsa20.state ->
incr: Spec.Salsa20.counter ->
len: Lib.IntTypes.size_nat{len < Spec.Salsa20.size_block} ->
b: Lib.ByteSequence.lbytes len
-> Lib.ByteSequence.lbytes len | {
"end_col": 18,
"end_line": 148,
"start_col": 34,
"start_line": 144
} |
Prims.Tot | val salsa20_update:
ctx: state
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let salsa20_update ctx msg =
let cipher = msg in
map_blocks size_block cipher
(salsa20_encrypt_block ctx)
(salsa20_encrypt_last ctx) | val salsa20_update:
ctx: state
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg}
let salsa20_update ctx msg = | false | null | false | let cipher = msg in
map_blocks size_block cipher (salsa20_encrypt_block ctx) (salsa20_encrypt_last ctx) | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.state",
"Lib.ByteSequence.bytes",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Salsa20.size_block",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.map_blocks",
"Spec.Salsa20.salsa20_encrypt_block",
"Spec.Salsa20.salsa20_encrypt_last",
"Lib.Sequence.seq",
"Lib.IntTypes.int_t",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.eq2",
"Prims.nat"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st
let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res
let salsa20_key_block (st:state) : Tot block =
let st' = salsa20_core 0 st in
uints_to_bytes_le st'
let salsa20_key_block0 (k:key) (n:nonce) : Tot block =
let st = salsa20_init k n 0 in
salsa20_key_block st
let xor_block (k:state) (b:block) : block =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
uints_to_bytes_le ob
let salsa20_encrypt_block (st0:state) (incr:counter) (b:block) : Tot block =
let k = salsa20_core incr st0 in
xor_block k b
let salsa20_encrypt_last (st0:state) (incr:counter)
(len:size_nat{len < size_block})
(b:lbytes len) : lbytes len =
let plain = create size_block (u8 0) in
let plain = update_sub plain 0 (length b) b in
let cipher = salsa20_encrypt_block st0 incr plain in
sub cipher 0 len
val salsa20_update:
ctx: state
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg} | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val salsa20_update:
ctx: state
-> msg: bytes{length msg / size_block <= max_size_t}
-> cipher: bytes{length cipher == length msg} | [] | Spec.Salsa20.salsa20_update | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
ctx: Spec.Salsa20.state ->
msg:
Lib.ByteSequence.bytes
{Lib.Sequence.length msg / Spec.Salsa20.size_block <= Lib.IntTypes.max_size_t}
-> cipher: Lib.ByteSequence.bytes{Lib.Sequence.length cipher == Lib.Sequence.length msg} | {
"end_col": 30,
"end_line": 159,
"start_col": 28,
"start_line": 155
} |
Prims.Tot | val hsalsa20 (k: key) (n: xnonce) : Tot (lbytes 32) | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let hsalsa20 (k:key) (n:xnonce) : Tot (lbytes 32) =
let st = hsalsa20_init k n in
let st = rounds st in
[@inline_let]
let res_l = [st.[0]; st.[5]; st.[10]; st.[15]; st.[6]; st.[7]; st.[8]; st.[9]] in
assert_norm(List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res | val hsalsa20 (k: key) (n: xnonce) : Tot (lbytes 32)
let hsalsa20 (k: key) (n: xnonce) : Tot (lbytes 32) = | false | null | false | let st = hsalsa20_init k n in
let st = rounds st in
[@@ inline_let ]let res_l =
[st.[ 0 ]; st.[ 5 ]; st.[ 10 ]; st.[ 15 ]; st.[ 6 ]; st.[ 7 ]; st.[ 8 ]; st.[ 9 ]]
in
assert_norm (List.Tot.length res_l == 8);
let res = createL res_l in
uints_to_bytes_le res | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.xnonce",
"Lib.ByteSequence.uints_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"FStar.List.Tot.Base.length",
"Lib.IntTypes.uint_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Properties.seq_of_list",
"Lib.Sequence.createL",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.int",
"Prims.list",
"Prims.Cons",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint32",
"Prims.Nil",
"Spec.Salsa20.state",
"Spec.Salsa20.rounds",
"Spec.Salsa20.hsalsa20_init",
"Lib.ByteSequence.lbytes"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st
let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let hsalsa20_init (k:key) (n:xnonce) : Tot state =
let st = create 16 (u32 0) in
let st = xsetup k n st in
st | false | false | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val hsalsa20 (k: key) (n: xnonce) : Tot (lbytes 32) | [] | Spec.Salsa20.hsalsa20 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Spec.Salsa20.key -> n: Spec.Salsa20.xnonce -> Lib.ByteSequence.lbytes 32 | {
"end_col": 23,
"end_line": 123,
"start_col": 51,
"start_line": 116
} |
Prims.Tot | val xsetup (k: key) (n: xnonce) (st: state) : Tot state | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let xsetup (k:key) (n:xnonce) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st | val xsetup (k: key) (n: xnonce) (st: state) : Tot state
let xsetup (k: key) (n: xnonce) (st: state) : Tot state = | false | null | false | let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #4 n in
let st = st.[ 0 ] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[ 5 ] <- constant1 in
let st = update_sub st 6 4 ns in
let st = st.[ 10 ] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[ 15 ] <- constant3 in
st | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.xnonce",
"Spec.Salsa20.state",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Spec.Salsa20.constant3",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.uint32",
"Lib.Sequence.sub",
"Lib.Sequence.slice",
"Prims.op_Addition",
"Lib.Sequence.update_sub",
"Lib.IntTypes.uint_t",
"Spec.Salsa20.constant2",
"Spec.Salsa20.constant1",
"Spec.Salsa20.constant0",
"Lib.ByteSequence.uints_from_bytes_le"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574
let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st
let salsa20_init (k:key) (n:nonce) (ctr0:counter) : Tot state =
let st = create 16 (u32 0) in
let st = setup k n ctr0 st in
st | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val xsetup (k: key) (n: xnonce) (st: state) : Tot state | [] | Spec.Salsa20.xsetup | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Spec.Salsa20.key -> n: Spec.Salsa20.xnonce -> st: Spec.Salsa20.state -> Spec.Salsa20.state | {
"end_col": 4,
"end_line": 109,
"start_col": 54,
"start_line": 99
} |
Prims.Tot | val setup (k: key) (n: nonce) (ctr0: counter) (st: state) : Tot state | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let setup (k:key) (n:nonce) (ctr0:counter) (st:state) : Tot state =
let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[0] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[5] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[8] <- u32 ctr0 in
let st = st.[9] <- u32 0 in
let st = st.[10] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[15] <- constant3 in
st | val setup (k: key) (n: nonce) (ctr0: counter) (st: state) : Tot state
let setup (k: key) (n: nonce) (ctr0: counter) (st: state) : Tot state = | false | null | false | let ks = uints_from_bytes_le #U32 #SEC #8 k in
let ns = uints_from_bytes_le #U32 #SEC #2 n in
let st = st.[ 0 ] <- constant0 in
let st = update_sub st 1 4 (slice ks 0 4) in
let st = st.[ 5 ] <- constant1 in
let st = update_sub st 6 2 ns in
let st = st.[ 8 ] <- u32 ctr0 in
let st = st.[ 9 ] <- u32 0 in
let st = st.[ 10 ] <- constant2 in
let st = update_sub st 11 4 (slice ks 4 8) in
let st = st.[ 15 ] <- constant3 in
st | {
"checked_file": "Spec.Salsa20.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
"total"
] | [
"Spec.Salsa20.key",
"Spec.Salsa20.nonce",
"Spec.Salsa20.counter",
"Spec.Salsa20.state",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Spec.Salsa20.constant3",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.uint32",
"Lib.Sequence.sub",
"Lib.Sequence.slice",
"Prims.op_Addition",
"Lib.Sequence.update_sub",
"Lib.IntTypes.uint_t",
"Spec.Salsa20.constant2",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.u32",
"Spec.Salsa20.constant1",
"Spec.Salsa20.constant0",
"Lib.ByteSequence.uints_from_bytes_le"
] | [] | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *)
let rounds : shuffle =
repeat 10 double_round (* 20 rounds *)
let salsa20_add_counter (s:state) (ctr:counter) : Tot state =
s.[8] <- s.[8] +. (u32 ctr)
let salsa20_core (ctr:counter) (s:state) : Tot state =
let s' = salsa20_add_counter s ctr in
let s' = rounds s' in
let s' = map2 (+.) s' s in
salsa20_add_counter s' ctr
(* state initialization *)
inline_for_extraction
let constant0 = u32 0x61707865
inline_for_extraction
let constant1 = u32 0x3320646e
inline_for_extraction
let constant2 = u32 0x79622d32
inline_for_extraction
let constant3 = u32 0x6b206574 | false | true | Spec.Salsa20.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val setup (k: key) (n: nonce) (ctr0: counter) (st: state) : Tot state | [] | Spec.Salsa20.setup | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Spec.Salsa20.key -> n: Spec.Salsa20.nonce -> ctr0: Spec.Salsa20.counter -> st: Spec.Salsa20.state
-> Spec.Salsa20.state | {
"end_col": 4,
"end_line": 92,
"start_col": 67,
"start_line": 80
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let blocksize = size_block | let blocksize = | false | null | false | size_block | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"total"
] | [
"Hacl.Spec.Chacha20.Vec.size_block"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" | false | true | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blocksize : Prims.int | [] | Hacl.Spec.Chacha20.Equiv.blocksize | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.int | {
"end_col": 26,
"end_line": 19,
"start_col": 16,
"start_line": 19
} |
|
Prims.Tot | val scalar_rounds (m: Scalar.state) : Scalar.state | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m))))))))) | val scalar_rounds (m: Scalar.state) : Scalar.state
let scalar_rounds (m: Scalar.state) : Scalar.state = | false | null | false | Scalar.double_round (Scalar.double_round (Scalar.double_round (Scalar.double_round (Scalar.double_round
(Scalar.double_round (Scalar.double_round (Scalar.double_round (Scalar.double_round
(Scalar.double_round m))))))))) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"total"
] | [
"Spec.Chacha20.state",
"Spec.Chacha20.double_round"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract | false | true | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val scalar_rounds (m: Scalar.state) : Scalar.state | [] | Hacl.Spec.Chacha20.Equiv.scalar_rounds | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Spec.Chacha20.state -> Spec.Chacha20.state | {
"end_col": 53,
"end_line": 229,
"start_col": 2,
"start_line": 225
} |
FStar.Pervasives.Lemma | val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9 | val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m = | false | null | true | let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9 | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Chacha20.state",
"Lib.LoopCombinators.unfold_repeat",
"Spec.Chacha20.double_round",
"Prims.unit",
"Lib.LoopCombinators.eq_repeat0"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m) | [] | Hacl.Spec.Chacha20.Equiv.scalar_rounds_unroll_lemma | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Spec.Chacha20.state
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Equiv.scalar_rounds m) (Spec.Chacha20.rounds m)) | {
"end_col": 42,
"end_line": 247,
"start_col": 2,
"start_line": 236
} |
FStar.Pervasives.Lemma | val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i]) | val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i = | false | null | true | let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[ i ]
(Scalar.quarter_round a b c d (transpose_state m).[ i ]) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.idx",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Hacl.Spec.Chacha20.Vec.quarter_round",
"Spec.Chacha20.quarter_round",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.line_lemma_i",
"Lib.IntTypes.size",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Chacha20.Vec.line"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i]) | [] | Hacl.Spec.Chacha20.Equiv.quarter_round_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Chacha20.Vec.idx ->
b: Hacl.Spec.Chacha20.Vec.idx ->
c: Hacl.Spec.Chacha20.Vec.idx ->
d: Hacl.Spec.Chacha20.Vec.idx ->
m: Hacl.Spec.Chacha20.Vec.state w ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.quarter_round
a
b
c
d
m)).[ i ]
(Spec.Chacha20.quarter_round a b c d (Hacl.Spec.Chacha20.Vec.transpose_state m).[ i ])) | {
"end_col": 58,
"end_line": 178,
"start_col": 42,
"start_line": 167
} |
FStar.Pervasives.Lemma | val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i | val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i = | false | null | true | let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.diagonal_round_lemma_i",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.column_round_lemma_i",
"Hacl.Spec.Chacha20.Vec.diagonal_round",
"Hacl.Spec.Chacha20.Vec.column_round"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i]) | [] | Hacl.Spec.Chacha20.Equiv.double_round_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Hacl.Spec.Chacha20.Vec.state w -> i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.double_round
m)).[ i ]
(Spec.Chacha20.double_round (Hacl.Spec.Chacha20.Vec.transpose_state m).[ i ])) | {
"end_col": 29,
"end_line": 220,
"start_col": 33,
"start_line": 216
} |
FStar.Pervasives.Lemma | val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i]) | val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i = | false | null | true | let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[ i ] (Scalar.column_round (transpose_state m).[ i ]) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Hacl.Spec.Chacha20.Vec.column_round",
"Spec.Chacha20.column_round",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.quarter_round_lemma_i",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Chacha20.Vec.quarter_round"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i]) | [] | Hacl.Spec.Chacha20.Equiv.column_round_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Hacl.Spec.Chacha20.Vec.state w -> i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.column_round
m)).[ i ]
(Spec.Chacha20.column_round (Hacl.Spec.Chacha20.Vec.transpose_state m).[ i ])) | {
"end_col": 98,
"end_line": 194,
"start_col": 33,
"start_line": 184
} |
FStar.Pervasives.Lemma | val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
} | val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i = | false | null | true | let bs = w * 4 in
calc ( == ) {
(i / bs) * bs + (i % bs / 4) * 4;
( == ) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
(i / bs) * bs + i % bs - i % bs % 4;
( == ) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
( == ) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
( == ) { Math.Lemmas.euclidean_division_definition i 4 }
(i / 4) * 4;
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.euclidean_division_definition",
"Prims.squash",
"FStar.Math.Lemmas.modulo_modulo_lemma"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} -> | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4) | [] | Hacl.Spec.Chacha20.Equiv.lemma_i_div_w4 | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | w: Prims.pos -> i: Prims.nat{i < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let bs = w * 4 in
(i / bs) * bs + (i % bs / 4) * 4 == (i / 4) * 4)) | {
"end_col": 5,
"end_line": 356,
"start_col": 24,
"start_line": 344
} |
FStar.Pervasives.Lemma | val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i]) | val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i = | false | null | true | let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[ i ]
(Scalar.diagonal_round (transpose_state m).[ i ]) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Hacl.Spec.Chacha20.Vec.diagonal_round",
"Spec.Chacha20.diagonal_round",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.quarter_round_lemma_i",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Chacha20.Vec.quarter_round"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i]) | [] | Hacl.Spec.Chacha20.Equiv.diagonal_round_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Hacl.Spec.Chacha20.Vec.state w -> i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.diagonal_round
m)).[ i ]
(Spec.Chacha20.diagonal_round (Hacl.Spec.Chacha20.Vec.transpose_state m).[ i ])) | {
"end_col": 102,
"end_line": 210,
"start_col": 35,
"start_line": 200
} |
FStar.Pervasives.Lemma | val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32) | val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b = | false | null | true | let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.op_Addition",
"Prims.nat",
"Prims.op_LessThan",
"Lib.IntTypes.uint32",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Lib.IntTypes.modulus",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.u32"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c)) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c)) | [] | Hacl.Spec.Chacha20.Equiv.add_counter_lemma_aux | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
w: Hacl.Spec.Chacha20.Vec.lanes ->
c0: Hacl.Spec.Chacha20.Vec.counter ->
c:
Hacl.Spec.Chacha20.Vec.counter
{w * c <= Lib.IntTypes.max_size_t /\ c0 + w <= Lib.IntTypes.max_size_t} ->
i: Prims.nat{i < w} ->
b: Lib.IntTypes.uint32
-> FStar.Pervasives.Lemma
(ensures
b +. Lib.IntTypes.u32 c0 +. Lib.IntTypes.u32 (w * c + i) ==
b +. Lib.IntTypes.u32 (c0 + i) +. Lib.IntTypes.u32 (w * c)) | {
"end_col": 73,
"end_line": 83,
"start_col": 38,
"start_line": 77
} |
FStar.Pervasives.Lemma | val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
} | val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i = | false | null | true | calc ( == ) {
(i / blocksize) * blocksize + (i % blocksize / 4) * 4;
( == ) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
(i / blocksize) * blocksize + i % blocksize - i % blocksize % 4;
( == ) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
(i / blocksize) * blocksize + i % blocksize - i % 4;
( == ) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
( == ) { Math.Lemmas.euclidean_division_definition i 4 }
(i / 4) * 4;
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.euclidean_division_definition",
"Prims.squash",
"FStar.Math.Lemmas.modulo_modulo_lemma"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4) | [] | Hacl.Spec.Chacha20.Equiv.lemma_i_div_blocksize | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | w: Prims.pos -> i: Prims.nat{i < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(i / Hacl.Spec.Chacha20.Equiv.blocksize) * Hacl.Spec.Chacha20.Equiv.blocksize +
(i % Hacl.Spec.Chacha20.Equiv.blocksize / 4) * 4 ==
(i / 4) * 4) | {
"end_col": 3,
"end_line": 371,
"start_col": 2,
"start_line": 361
} |
FStar.Pervasives.Lemma | val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms | val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i = | false | null | true | let ms = (transpose_state m).[ i ] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[ i ] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.scalar_rounds_unroll_lemma",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Hacl.Spec.Chacha20.Equiv.scalar_rounds",
"Hacl.Spec.Chacha20.Equiv.double_round_lemma_i",
"Hacl.Spec.Chacha20.Vec.rounds",
"Hacl.Spec.Chacha20.Vec.double_round",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i]) | [] | Hacl.Spec.Chacha20.Equiv.rounds_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Hacl.Spec.Chacha20.Vec.state w -> i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.rounds m)
).[ i ]
(Spec.Chacha20.rounds (Hacl.Spec.Chacha20.Vec.transpose_state m).[ i ])) | {
"end_col": 31,
"end_line": 277,
"start_col": 27,
"start_line": 253
} |
FStar.Pervasives.Lemma | val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros) | val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v = | false | null | true | let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.size_pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Lib.Sequence.eq_intro",
"FStar.Seq.Base.append",
"Prims.unit",
"FStar.Seq.Properties.lemma_split",
"Prims.op_Subtraction",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.Sequence.sub",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Lib.Sequence.update_sub"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros) | [] | Hacl.Spec.Chacha20.Equiv.update_sub_is_append | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
zero: a ->
blocksize: Lib.IntTypes.size_pos ->
len: Prims.nat{len < blocksize} ->
b_v: Lib.Sequence.lseq a len
-> FStar.Pervasives.Lemma
(ensures
(let plain = Lib.Sequence.create blocksize zero in
let plain = Lib.Sequence.update_sub plain 0 len b_v in
let zeros = Lib.Sequence.create (blocksize - len) zero in
plain == FStar.Seq.Base.append b_v zeros)) | {
"end_col": 39,
"end_line": 594,
"start_col": 52,
"start_line": 588
} |
FStar.Pervasives.Lemma | val chacha20_map_blocks_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_map_blocks_vec_equiv_pre_k #w k n c0 hi_fv rem b_v j =
if j < rem / blocksize * blocksize then
chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j
else
chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j | val chacha20_map_blocks_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k #w k n c0 hi_fv rem b_v j = | false | null | true | if j < (rem / blocksize) * blocksize
then chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j
else chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.size_nat",
"FStar.Mul.op_Star",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Prims.op_Division",
"Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k0",
"Prims.bool",
"Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k1",
"Prims.unit"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else ()
val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
//assert (j / blocksize < w);
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert (j / blocksize * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert (j / blocksize * blocksize + k == len / blocksize * blocksize + k);
calc (==) {
//Seq.index b k;
//(==) { }
Seq.index (Seq.slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain_v (j / blocksize * blocksize + k);
(==) { }
Seq.index plain_v (len / blocksize * blocksize + k);
}
val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain)
let update_sub_get_last_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
let aux (k:nat{k < blocksize}) : Lemma (Seq.index b k == Seq.index plain k) =
update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k;
update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k in
Classical.forall_intro aux;
eq_intro b plain
#set-options "--using_facts_from '* -FStar.Seq.Properties.slice_slice'"
val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_block_s #uint8 #rem blocksize b_v j in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_block_lemma w blocksize (u8 0) rem b_v j }
Seq.index (f (w * hi_fv + j / blocksize) b1) (j % blocksize);
}
val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_last_s #uint8 #rem blocksize b_v in
let plain = create blocksize (u8 0) in
let plain = update_sub plain 0 (rem % blocksize) b1 in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_last_lemma w blocksize (u8 0) rem b_v j; mod_div_lt blocksize j rem }
Seq.index (f (w * hi_fv + j / blocksize) plain) (j % blocksize);
(==) { }
Seq.index (g (w * hi_fv + j / blocksize) (rem % blocksize) b1) (j % blocksize);
}
val chacha20_map_blocks_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_map_blocks_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
hi_fv: Lib.IntTypes.size_nat{w * hi_fv + w <= Lib.IntTypes.max_size_t} ->
rem: Prims.nat{rem < w * Hacl.Spec.Chacha20.Equiv.blocksize} ->
b_v: Lib.Sequence.lseq Lib.IntTypes.uint8 rem ->
j: Prims.nat{j < rem}
-> FStar.Pervasives.Lemma
(ensures
(let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in
let st0 = Spec.Chacha20.chacha20_init k n c0 in
let g_v = Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last st_v0 in
let f = Spec.Chacha20.chacha20_encrypt_block st0 in
let g = Spec.Chacha20.chacha20_encrypt_last st0 in
Lib.Vec.Lemmas.map_blocks_vec_equiv_pre_k w
Hacl.Spec.Chacha20.Equiv.blocksize
hi_fv
f
g
g_v
rem
b_v
j)) | {
"end_col": 66,
"end_line": 922,
"start_col": 2,
"start_line": 919
} |
FStar.Pervasives.Lemma | val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i]) | val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i = | false | null | true | eq_intro (transpose_state (sum_state st1 st2)).[ i ]
(Scalar.sum_state (transpose_state st1).[ i ] (transpose_state st2).[ i ]) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Hacl.Spec.Chacha20.Vec.sum_state",
"Spec.Chacha20.sum_state",
"Prims.unit"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i]) | [] | Hacl.Spec.Chacha20.Equiv.sum_state_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st1: Hacl.Spec.Chacha20.Vec.state w -> st2: Hacl.Spec.Chacha20.Vec.state w -> i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.sum_state
st1
st2)).[ i ]
(Spec.Chacha20.sum_state (Hacl.Spec.Chacha20.Vec.transpose_state st1).[ i ]
(Hacl.Spec.Chacha20.Vec.transpose_state st2).[ i ])) | {
"end_col": 123,
"end_line": 284,
"start_col": 2,
"start_line": 284
} |
FStar.Pervasives.Lemma | val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p | val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j = | false | null | true | let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Prims.op_Division",
"Lib.Sequence.eq_intro",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.Lemmas.get_block_s",
"Lib.Sequence.update_sub",
"Lib.Sequence.create",
"Hacl.Spec.Chacha20.Equiv.update_sub_get_block_lemma_k",
"FStar.Math.Lemmas.cancel_mul_div",
"Lib.Sequence.div_mul_lt",
"Prims.l_and",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.l_or",
"Prims.op_Addition",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Prims.l_imp",
"Prims.int"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j) | [] | Hacl.Spec.Chacha20.Equiv.update_sub_get_block_lemma | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
w: Lib.IntTypes.size_pos ->
blocksize: Lib.IntTypes.size_pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
zero: a ->
len: Prims.nat{len < w * blocksize} ->
b_v: Lib.Sequence.lseq a len ->
j: Prims.nat{j < (len / blocksize) * blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let blocksize_v = w * blocksize in
let plain_v = Lib.Sequence.create blocksize_v zero in
let plain_v = Lib.Sequence.update_sub plain_v 0 len b_v in
[@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.div_mul_lt blocksize j w in
[@@ FStar.Pervasives.inline_let ]let _ = FStar.Math.Lemmas.cancel_mul_div w blocksize in
Lib.Sequence.Lemmas.get_block_s blocksize plain_v j ==
Lib.Sequence.Lemmas.get_block_s blocksize b_v j)) | {
"end_col": 16,
"end_line": 680,
"start_col": 62,
"start_line": 670
} |
FStar.Pervasives.Lemma | val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update_sub_get_last_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
let aux (k:nat{k < blocksize}) : Lemma (Seq.index b k == Seq.index plain k) =
update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k;
update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k in
Classical.forall_intro aux;
eq_intro b plain | val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain)
let update_sub_get_last_lemma #a w blocksize zero len b_v j = | false | null | true | let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
let aux (k: nat{k < blocksize}) : Lemma (Seq.index b k == Seq.index plain k) =
update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k;
update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k
in
Classical.forall_intro aux;
eq_intro b plain | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.op_Division",
"Lib.Sequence.eq_intro",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma_plain_v_k",
"Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma_plain_k",
"Lib.Sequence.Lemmas.get_block_s",
"Prims.op_Modulus",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.l_or",
"Prims.op_Addition",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Prims.l_imp",
"Lib.Sequence.create",
"Lib.Sequence.Lemmas.get_last_s",
"FStar.Math.Lemmas.cancel_mul_div",
"Lib.Sequence.div_mul_lt",
"Prims.int"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else ()
val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
//assert (j / blocksize < w);
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert (j / blocksize * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert (j / blocksize * blocksize + k == len / blocksize * blocksize + k);
calc (==) {
//Seq.index b k;
//(==) { }
Seq.index (Seq.slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain_v (j / blocksize * blocksize + k);
(==) { }
Seq.index plain_v (len / blocksize * blocksize + k);
}
val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain) | [] | Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
w: Lib.IntTypes.size_pos ->
blocksize: Lib.IntTypes.size_pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
zero: a ->
len: Prims.nat{len < w * blocksize} ->
b_v: Lib.Sequence.lseq a len ->
j: Prims.nat{(len / blocksize) * blocksize <= j /\ j < len}
-> FStar.Pervasives.Lemma
(ensures
(let blocksize_v = w * blocksize in
let plain_v = Lib.Sequence.create blocksize_v zero in
let plain_v = Lib.Sequence.update_sub plain_v 0 len b_v in
[@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.div_mul_lt blocksize j w in
[@@ FStar.Pervasives.inline_let ]let _ = FStar.Math.Lemmas.cancel_mul_div w blocksize in
let block_l = Lib.Sequence.Lemmas.get_last_s blocksize b_v in
let plain = Lib.Sequence.create blocksize zero in
let plain = Lib.Sequence.update_sub plain 0 (len % blocksize) block_l in
Lib.Sequence.Lemmas.get_block_s blocksize plain_v j == plain)) | {
"end_col": 18,
"end_line": 808,
"start_col": 61,
"start_line": 791
} |
FStar.Pervasives.Lemma | val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
} | val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i = | false | null | true | let ib = uints_from_bytes_le b in
let ob = map2 ( ^. ) ib k in
let b_i = sub b ((i / 4) * 4) 4 in
calc ( == ) {
Seq.index (uints_to_bytes_le ob) i;
( == ) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[ i / 4 ]) (i % 4);
( == ) { () }
Seq.index (uint_to_bytes_le (ib.[ i / 4 ] ^. k.[ i / 4 ])) (i % 4);
( == ) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[ i / 4 ])) (i % 4);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Spec.Chacha20.state",
"Spec.Chacha20.block",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.ByteSequence.uints_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.ByteSequence.uint_to_bytes_le",
"Lib.IntTypes.op_Hat_Dot",
"Lib.ByteSequence.uint_from_bytes_le",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint32",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.ByteSequence.index_uints_to_bytes_le",
"Prims.squash",
"Lib.ByteSequence.index_uints_from_bytes_le",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Spec.Chacha20.size_block",
"Prims.op_Multiply",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.l_or",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"FStar.Mul.op_Star",
"Prims.l_imp",
"Lib.IntTypes.logxor",
"Lib.Sequence.map2",
"Lib.ByteSequence.uints_from_bytes_le"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4]) | [] | Hacl.Spec.Chacha20.Equiv.xor_block_scalar_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Spec.Chacha20.state ->
b: Spec.Chacha20.block ->
i: Prims.nat{i < Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(Spec.Chacha20.xor_block k b).[ i ] ==
(Lib.ByteSequence.uint_to_bytes_le (Lib.ByteSequence.uint_from_bytes_le (Lib.Sequence.sub b
((i / 4) * 4)
4) ^.
k.[ i / 4 ])).[ i % 4 ]) | {
"end_col": 5,
"end_line": 425,
"start_col": 36,
"start_line": 412
} |
FStar.Pervasives.Lemma | val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i | val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i = | false | null | true | let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.op_Addition",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.chacha20_core_scalar_lemma",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.chacha20_init_scalar_lemma",
"Spec.Chacha20.state",
"Spec.Chacha20.chacha20_init"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) | [] | Hacl.Spec.Chacha20.Equiv.kb_equiv_lemma | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter ->
c:
Hacl.Spec.Chacha20.Vec.counter
{w * c <= Lib.IntTypes.max_size_t /\ c0 + w <= Lib.IntTypes.max_size_t} ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
(let st1 = Spec.Chacha20.chacha20_init k n c0 in
let st2 = Spec.Chacha20.chacha20_init k n (c0 + i) in
FStar.Seq.Base.equal (Spec.Chacha20.chacha20_core (w * c + i) st1)
(Spec.Chacha20.chacha20_core (w * c) st2))) | {
"end_col": 45,
"end_line": 136,
"start_col": 34,
"start_line": 131
} |
FStar.Pervasives.Lemma | val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c)) | val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i = | false | null | true | Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[ i ]
(Scalar.chacha20_add_counter (transpose_state st).[ i ] (w * c)) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Hacl.Spec.Chacha20.Vec.add_counter",
"Spec.Chacha20.chacha20_add_counter",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.IntTypes.range_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.u32",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.pow2"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c)) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c)) | [] | Hacl.Spec.Chacha20.Equiv.add_counter_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
st: Hacl.Spec.Chacha20.Vec.state w ->
c: Hacl.Spec.Chacha20.Vec.counter{w * c <= Lib.IntTypes.max_size_t} ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.add_counter
c
st)).[ i ]
(Spec.Chacha20.chacha20_add_counter (Hacl.Spec.Chacha20.Vec.transpose_state st).[ i ]
(w * c))) | {
"end_col": 117,
"end_line": 293,
"start_col": 2,
"start_line": 291
} |
FStar.Pervasives.Lemma | val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else () | val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k = | false | null | true | let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize
then
calc ( == ) {
Seq.index plain k;
( == ) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
( == ) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
( == ) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v ((len / blocksize) * blocksize + k);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.op_Division",
"Prims.op_Modulus",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Seq.Base.lemma_index_app1",
"Prims.squash",
"FStar.Seq.Base.lemma_index_slice",
"FStar.Math.Lemmas.euclidean_division_definition",
"Prims.bool",
"Prims._assert",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append",
"Hacl.Spec.Chacha20.Equiv.update_sub_is_append",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.Sequence.sub",
"Prims.l_or",
"Lib.Sequence.update_sub",
"Lib.Sequence.Lemmas.get_last_s"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero)) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero)) | [] | Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma_plain_k | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
w: Lib.IntTypes.size_pos ->
blocksize: Lib.IntTypes.size_pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
zero: a ->
len: Prims.nat{len < w * blocksize} ->
b_v: Lib.Sequence.lseq a len ->
j: Prims.nat{(len / blocksize) * blocksize <= j /\ j < len} ->
k: Prims.nat{k < blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let block_l = Lib.Sequence.Lemmas.get_last_s blocksize b_v in
let plain = Lib.Sequence.create blocksize zero in
let plain = Lib.Sequence.update_sub plain 0 (len % blocksize) block_l in
FStar.Seq.Base.index plain k ==
(match k < len % blocksize with
| true -> FStar.Seq.Base.index b_v ((len / blocksize) * blocksize + k)
| _ -> zero))) | {
"end_col": 9,
"end_line": 718,
"start_col": 71,
"start_line": 699
} |
FStar.Pervasives.Lemma | val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
//assert (j / blocksize < w);
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert (j / blocksize * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert (j / blocksize * blocksize + k == len / blocksize * blocksize + k);
calc (==) {
//Seq.index b k;
//(==) { }
Seq.index (Seq.slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain_v (j / blocksize * blocksize + k);
(==) { }
Seq.index plain_v (len / blocksize * blocksize + k);
} | val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k = | false | null | true | let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert ((j / blocksize) * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert ((j / blocksize) * blocksize + k == (len / blocksize) * blocksize + k);
calc ( == ) {
Seq.index (Seq.slice plain_v
((j / blocksize) * blocksize)
((j / blocksize) * blocksize + blocksize))
k;
( == ) { Seq.lemma_index_slice plain_v
((j / blocksize) * blocksize)
((j / blocksize) * blocksize + blocksize)
k }
Seq.index plain_v ((j / blocksize) * blocksize + k);
( == ) { () }
Seq.index plain_v ((len / blocksize) * blocksize + k);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.op_Division",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Seq.Base.lemma_index_slice",
"Prims.squash",
"Prims._assert",
"Prims.int",
"Lib.Sequence.div_interval",
"FStar.Math.Lemmas.lemma_mult_le_right",
"Lib.Sequence.Lemmas.get_block_s",
"FStar.Math.Lemmas.cancel_mul_div",
"Lib.Sequence.div_mul_lt",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append",
"Hacl.Spec.Chacha20.Equiv.update_sub_is_append",
"Prims.op_Subtraction",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Lib.Sequence.sub",
"Prims.l_or",
"Lib.Sequence.update_sub"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else ()
val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero)) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero)) | [] | Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma_plain_v_k | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
w: Lib.IntTypes.size_pos ->
blocksize: Lib.IntTypes.size_pos{w * blocksize <= Lib.IntTypes.max_size_t} ->
zero: a ->
len: Prims.nat{len < w * blocksize} ->
b_v: Lib.Sequence.lseq a len ->
j: Prims.nat{(len / blocksize) * blocksize <= j /\ j < len} ->
k: Prims.nat{k < blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let blocksize_v = w * blocksize in
let plain_v = Lib.Sequence.create blocksize_v zero in
let plain_v = Lib.Sequence.update_sub plain_v 0 len b_v in
[@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.div_mul_lt blocksize j w in
[@@ FStar.Pervasives.inline_let ]let _ = FStar.Math.Lemmas.cancel_mul_div w blocksize in
let b = Lib.Sequence.Lemmas.get_block_s blocksize plain_v j in
[@@ FStar.Pervasives.inline_let ]let _ =
Lib.Sequence.div_interval blocksize (len / blocksize) j
in
FStar.Seq.Base.index b k ==
(match k < len % blocksize with
| true -> FStar.Seq.Base.index b_v ((len / blocksize) * blocksize + k)
| _ -> zero))) | {
"end_col": 5,
"end_line": 767,
"start_col": 73,
"start_line": 741
} |
FStar.Pervasives.Lemma | val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
} | val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i = | false | null | true | let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[ i / blocksize ] in
calc ( == ) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
( == ) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
( == ) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
( == ) { (Lemmas.transpose_lemma_index #w k (i / 4);
Math.Lemmas.division_multiplication_lemma i 4 16) }
Seq.index ki (i / 4 % 16);
( == ) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.IntVector.vec_v",
"Hacl.Spec.Chacha20.Vec.uint32xN",
"Hacl.Spec.Chacha20.Vec.transpose",
"Prims.op_Division",
"Prims.op_Modulus",
"Lib.IntTypes.uint32",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.modulo_division_lemma",
"Prims.squash",
"FStar.Math.Lemmas.division_multiplication_lemma",
"Hacl.Spec.Chacha20.Lemmas.transpose_lemma_index",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.Sequence.to_seq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Lib.Sequence.op_String_Access",
"Prims.int"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4)) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4)) | [] | Hacl.Spec.Chacha20.Equiv.transpose_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Hacl.Spec.Chacha20.Vec.state w -> i: Prims.nat{i < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (Lib.IntVector.vec_v (FStar.Seq.Base.index (Hacl.Spec.Chacha20.Vec.transpose
k)
(i / (w * 4))))
(i % (w * 4) / 4) ==
FStar.Seq.Base.index (FStar.Seq.Base.index (Hacl.Spec.Chacha20.Vec.transpose_state k)
(i / Hacl.Spec.Chacha20.Equiv.blocksize))
(i % Hacl.Spec.Chacha20.Equiv.blocksize / 4)) | {
"end_col": 5,
"end_line": 446,
"start_col": 30,
"start_line": 432
} |
FStar.Pervasives.Lemma | val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i | val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i = | false | null | true | let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.add_counter_lemma_i",
"Hacl.Spec.Chacha20.Vec.add_counter",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.sum_state_lemma_i",
"Hacl.Spec.Chacha20.Vec.sum_state",
"Hacl.Spec.Chacha20.Equiv.rounds_lemma_i",
"Hacl.Spec.Chacha20.Vec.rounds"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i]) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_core_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
c: Hacl.Spec.Chacha20.Vec.counter{w * c <= Lib.IntTypes.max_size_t} ->
st_v0: Hacl.Spec.Chacha20.Vec.state w ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.chacha20_core
c
st_v0)).[ i ]
(Spec.Chacha20.chacha20_core (w * c) (Hacl.Spec.Chacha20.Vec.transpose_state st_v0).[ i ])) | {
"end_col": 28,
"end_line": 307,
"start_col": 40,
"start_line": 299
} |
FStar.Pervasives.Lemma | val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j | val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j = | false | null | true | let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Chacha20.Vec.blocks",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Hacl.Spec.Chacha20.Equiv.xor_block_lemma_i",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.chacha20_core_lemma_i",
"Prims.op_Division",
"Hacl.Spec.Chacha20.Vec.chacha20_core"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize]) | [] | Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_st0_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
st_v0: Hacl.Spec.Chacha20.Vec.state w ->
c: Hacl.Spec.Chacha20.Vec.counter{w * c <= Lib.IntTypes.max_size_t} ->
b_v: Hacl.Spec.Chacha20.Vec.blocks w ->
j: Prims.nat{j < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
([@@ FStar.Pervasives.inline_let ]let _ =
FStar.Math.Lemmas.cancel_mul_div w Hacl.Spec.Chacha20.Equiv.blocksize
in
let b = Lib.Sequence.Lemmas.get_block_s Hacl.Spec.Chacha20.Equiv.blocksize b_v j in
[@@ FStar.Pervasives.inline_let ]let _ =
Lib.Sequence.div_mul_lt Hacl.Spec.Chacha20.Equiv.blocksize j w
in
(Hacl.Spec.Chacha20.Vec.chacha20_encrypt_block st_v0 c b_v).[ j ] ==
(Spec.Chacha20.chacha20_encrypt_block (Hacl.Spec.Chacha20.Vec.transpose_state st_v0).[ j /
Hacl.Spec.Chacha20.Equiv.blocksize ]
(w * c)
b).[ j % Hacl.Spec.Chacha20.Equiv.blocksize ])) | {
"end_col": 30,
"end_line": 521,
"start_col": 48,
"start_line": 518
} |
FStar.Pervasives.Lemma | val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2 | val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i = | false | null | true | let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[ 12 ] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[ 12 ] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[ 12 ] == v k2.[ 12 ]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[ 12 ] == k.[ 12 ] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[ 12 ] == k.[ 12 ] +. u32 (c0 + i));
assert (forall (j: nat). j < 16 /\ j <> 12 ==> k1.[ j ] == k2.[ j ]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[ 12 ] == k.[ 12 ] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[ 12 ] == k.[ 12 ] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[ 12 ];
eq_intro k1 k2 | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Spec.Chacha20.state",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.op_Addition",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.add_counter_lemma_aux",
"Lib.Sequence.op_String_Access",
"Prims._assert",
"Prims.eq2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.u32",
"Spec.Chacha20.chacha20_add_counter",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.op_disEquality",
"Prims.int",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Spec.Chacha20.sum_state",
"Spec.Chacha20.rounds",
"Lib.IntTypes.range_t",
"Lib.IntTypes.v"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_core_scalar_lemma | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
w: Hacl.Spec.Chacha20.Vec.lanes ->
st1: Spec.Chacha20.state ->
st2: Spec.Chacha20.state ->
c0: Hacl.Spec.Chacha20.Vec.counter ->
c:
Hacl.Spec.Chacha20.Vec.counter
{w * c <= Lib.IntTypes.max_size_t /\ c0 + w <= Lib.IntTypes.max_size_t} ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(requires
forall (j: Prims.nat).
j < 16 /\ j <> 12 ==>
st1.[ j ] == st2.[ j ] /\ st1.[ 12 ] == Lib.IntTypes.u32 c0 /\
st2.[ 12 ] == Lib.IntTypes.u32 (c0 + i))
(ensures
FStar.Seq.Base.equal (Spec.Chacha20.chacha20_core (w * c + i) st1)
(Spec.Chacha20.chacha20_core (w * c) st2)) | {
"end_col": 16,
"end_line": 117,
"start_col": 49,
"start_line": 99
} |
FStar.Pervasives.Lemma | val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2) | val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 = | false | null | true | let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[ 12 ] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"FStar.Seq.Properties.lemma_split",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.op_Addition",
"Prims.unit",
"Lib.Sequence.sub",
"Lib.Sequence.eq_intro",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Prims.eq2",
"Lib.ByteSequence.uints_from_bytes_le",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"Lib.IntTypes.mk_int",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_disEquality",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.u32",
"Lib.Sequence.map",
"Lib.IntTypes.PUB",
"Lib.IntTypes.secret",
"Hacl.Spec.Chacha20.Vec.chacha20_constants",
"FStar.Seq.Base.create",
"Lib.Sequence.create",
"FStar.Seq.Base.append",
"Lib.Sequence.concat",
"Prims.int",
"Prims._assert",
"Lib.Sequence.op_At_Bar"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_init_scalar_lemma | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter
-> FStar.Pervasives.Lemma
(ensures
(let uc = Lib.Sequence.map Lib.IntTypes.secret Hacl.Spec.Chacha20.Vec.chacha20_constants in
let uk = Lib.ByteSequence.uints_from_bytes_le k in
let uctr = Lib.Sequence.create 1 (Lib.IntTypes.u32 c0) in
let un = Lib.ByteSequence.uints_from_bytes_le n in
Spec.Chacha20.chacha20_init k n c0 == uc @| uk @| uctr @| un)) | {
"end_col": 54,
"end_line": 66,
"start_col": 39,
"start_line": 32
} |
FStar.Pervasives.Lemma | val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i | val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i = | false | null | true | let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[ i ] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.op_Addition",
"Spec.Chacha20.block",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.kb_equiv_lemma",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Spec.Chacha20.chacha20_init",
"Hacl.Spec.Chacha20.Equiv.chacha20_init_lemma_i",
"Spec.Chacha20.state",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.chacha20_init"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i) | [] | Hacl.Spec.Chacha20.Equiv.encrypt_block_scalar_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter ->
c:
Hacl.Spec.Chacha20.Vec.counter
{w * c <= Lib.IntTypes.max_size_t /\ c0 + w <= Lib.IntTypes.max_size_t} ->
b_i: Spec.Chacha20.block ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
(let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in
let st0 = Spec.Chacha20.chacha20_init k n c0 in
FStar.Seq.Base.equal (Spec.Chacha20.chacha20_encrypt_block st0 (w * c + i) b_i)
(Spec.Chacha20.chacha20_encrypt_block (Hacl.Spec.Chacha20.Vec.transpose_state st_v0).[ i ]
(w * c)
b_i))) | {
"end_col": 30,
"end_line": 502,
"start_col": 50,
"start_line": 497
} |
FStar.Pervasives.Lemma | val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
} | val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i = | false | null | true | let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[ j ] in
let b_j = sub b ((i / bs) * bs) bs in
let b_i = sub b_j ((i % bs / 4) * 4) 4 in
let block = sub b ((i / 4) * 4) 4 in
let ob = map2 ( ^. ) (uints_from_bytes_le b_j) kb_j in
calc ( == ) {
Seq.index (xor_block k b) i;
( == ) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
( == ) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[ i % bs / 4 ]) (i % bs % 4);
( == ) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[ i % bs / 4 ]) (i % 4);
( == ) { () }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[ i % bs / 4 ] ^.
kb_j.[ i % bs / 4 ]))
(i % 4);
( == ) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[ i % bs / 4 ])) (i % 4);
( == ) { (lemma_i_div_w4 w i;
Seq.slice_slice b (j * bs) (j * bs + bs) ((i % bs / 4) * 4) ((i % bs / 4) * 4 + 4)) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[ i % bs / 4 ])) (i % 4);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.blocks",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.index",
"Hacl.Spec.Chacha20.Vec.xor_block",
"Lib.ByteSequence.uint_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.op_Hat_Dot",
"Lib.ByteSequence.uint_from_bytes_le",
"Lib.Sequence.op_String_Access",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Lib.ByteSequence.uints_from_bytes_le",
"Lib.ByteSequence.uints_to_bytes_le",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.Sequence.index_map_blocks_multi",
"Hacl.Spec.Chacha20.Vec.xor_block_f",
"Prims.squash",
"Lib.ByteSequence.index_uints_to_bytes_le",
"FStar.Math.Lemmas.modulo_modulo_lemma",
"Lib.ByteSequence.index_uints_from_bytes_le",
"FStar.Seq.Properties.slice_slice",
"Prims.op_Addition",
"Hacl.Spec.Chacha20.Equiv.lemma_i_div_w4",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Lib.IntTypes.logxor",
"Lib.Sequence.map2",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Multiply",
"Prims.l_or",
"Lib.Sequence.sub",
"Lib.IntVector.vec_v_t",
"Lib.IntVector.vec_v",
"Hacl.Spec.Chacha20.Vec.uint32xN",
"Prims.int"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4)) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4)) | [] | Hacl.Spec.Chacha20.Equiv.xor_block_vec_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.state w ->
b: Hacl.Spec.Chacha20.Vec.blocks w ->
i: Prims.nat{i < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let bs = w * 4 in
let j = i / bs in
let block = Lib.Sequence.sub b ((i / 4) * 4) 4 in
FStar.Seq.Base.index (Hacl.Spec.Chacha20.Vec.xor_block k b) i ==
FStar.Seq.Base.index (Lib.ByteSequence.uint_to_bytes_le (Lib.ByteSequence.uint_from_bytes_le
block ^.
FStar.Seq.Base.index (Lib.IntVector.vec_v k.[ j ]) (i % bs / 4)))
(i % 4))) | {
"end_col": 5,
"end_line": 406,
"start_col": 36,
"start_line": 381
} |
FStar.Pervasives.Lemma | val lemma_chacha20_vec_equiv:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> msg:seq uint8{length msg <= max_size_t} ->
Lemma (chacha20_encrypt_bytes #w k n c0 msg `Seq.equal` Scalar.chacha20_encrypt_bytes k n c0 msg) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lemma_chacha20_vec_equiv #w k n c0 msg =
let blocksize_v = w * blocksize in
let res = Scalar.chacha20_encrypt_bytes k n c0 msg in
let res_v = chacha20_encrypt_bytes #w k n c0 msg in
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
assert (res_v == map_blocks blocksize_v msg f_v g_v);
assert (res == map_blocks blocksize msg f g);
let hi_fv = length msg / blocksize_v in
let hi_f = w * hi_fv in
Classical.forall_intro_3 (chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f);
Classical.forall_intro_3 (chacha20_map_blocks_vec_equiv_pre_k #w k n c0 hi_fv);
VecLemmas.lemma_map_blocks_vec w blocksize msg hi_fv f g f_v g_v | val lemma_chacha20_vec_equiv:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> msg:seq uint8{length msg <= max_size_t} ->
Lemma (chacha20_encrypt_bytes #w k n c0 msg `Seq.equal` Scalar.chacha20_encrypt_bytes k n c0 msg)
let lemma_chacha20_vec_equiv #w k n c0 msg = | false | null | true | let blocksize_v = w * blocksize in
let res = Scalar.chacha20_encrypt_bytes k n c0 msg in
let res_v = chacha20_encrypt_bytes #w k n c0 msg in
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
assert (res_v == map_blocks blocksize_v msg f_v g_v);
assert (res == map_blocks blocksize msg f g);
let hi_fv = length msg / blocksize_v in
let hi_f = w * hi_fv in
Classical.forall_intro_3 (chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f);
Classical.forall_intro_3 (chacha20_map_blocks_vec_equiv_pre_k #w k n c0 hi_fv);
VecLemmas.lemma_map_blocks_vec w blocksize msg hi_fv f g f_v g_v | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.seq",
"Lib.IntTypes.uint8",
"Lib.Sequence.length",
"Lib.Vec.Lemmas.lemma_map_blocks_vec",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Prims.unit",
"FStar.Classical.forall_intro_3",
"Prims.nat",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.Sequence.lseq",
"Lib.Vec.Lemmas.map_blocks_vec_equiv_pre_k",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Chacha20.chacha20_encrypt_block",
"Spec.Chacha20.chacha20_init",
"Spec.Chacha20.chacha20_encrypt_last",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last",
"Hacl.Spec.Chacha20.Vec.chacha20_init",
"Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k",
"Lib.Vec.Lemmas.map_blocks_multi_vec_equiv_pre_k",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_block",
"Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_multi_vec_equiv_pre_k",
"Prims.int",
"Prims.op_Division",
"Prims._assert",
"Prims.eq2",
"Prims.l_or",
"Lib.Sequence.map_blocks",
"Spec.Chacha20.counter",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Chacha20.size_block",
"Lib.IntTypes.int_t",
"Spec.Chacha20.block",
"Prims.op_Multiply",
"Hacl.Spec.Chacha20.Vec.size_block",
"Hacl.Spec.Chacha20.Vec.blocks",
"Spec.Chacha20.state",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_bytes",
"Spec.Chacha20.chacha20_encrypt_bytes"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else ()
val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
//assert (j / blocksize < w);
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert (j / blocksize * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert (j / blocksize * blocksize + k == len / blocksize * blocksize + k);
calc (==) {
//Seq.index b k;
//(==) { }
Seq.index (Seq.slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain_v (j / blocksize * blocksize + k);
(==) { }
Seq.index plain_v (len / blocksize * blocksize + k);
}
val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain)
let update_sub_get_last_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
let aux (k:nat{k < blocksize}) : Lemma (Seq.index b k == Seq.index plain k) =
update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k;
update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k in
Classical.forall_intro aux;
eq_intro b plain
#set-options "--using_facts_from '* -FStar.Seq.Properties.slice_slice'"
val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_block_s #uint8 #rem blocksize b_v j in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_block_lemma w blocksize (u8 0) rem b_v j }
Seq.index (f (w * hi_fv + j / blocksize) b1) (j % blocksize);
}
val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_last_s #uint8 #rem blocksize b_v in
let plain = create blocksize (u8 0) in
let plain = update_sub plain 0 (rem % blocksize) b1 in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_last_lemma w blocksize (u8 0) rem b_v j; mod_div_lt blocksize j rem }
Seq.index (f (w * hi_fv + j / blocksize) plain) (j % blocksize);
(==) { }
Seq.index (g (w * hi_fv + j / blocksize) (rem % blocksize) b1) (j % blocksize);
}
val chacha20_map_blocks_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k #w k n c0 hi_fv rem b_v j =
if j < rem / blocksize * blocksize then
chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j
else
chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j
////////////////////////
// End of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val lemma_chacha20_vec_equiv:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> msg:seq uint8{length msg <= max_size_t} ->
Lemma (chacha20_encrypt_bytes #w k n c0 msg `Seq.equal` Scalar.chacha20_encrypt_bytes k n c0 msg) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lemma_chacha20_vec_equiv:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> msg:seq uint8{length msg <= max_size_t} ->
Lemma (chacha20_encrypt_bytes #w k n c0 msg `Seq.equal` Scalar.chacha20_encrypt_bytes k n c0 msg) | [] | Hacl.Spec.Chacha20.Equiv.lemma_chacha20_vec_equiv | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
msg: Lib.Sequence.seq Lib.IntTypes.uint8 {Lib.Sequence.length msg <= Lib.IntTypes.max_size_t}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.chacha20_encrypt_bytes k n c0 msg)
(Spec.Chacha20.chacha20_encrypt_bytes k n c0 msg)) | {
"end_col": 66,
"end_line": 957,
"start_col": 44,
"start_line": 936
} |
FStar.Pervasives.Lemma | val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2 | val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i = | false | null | true | let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[ 12 ] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[ i ] st1;
assert ((transpose_state st).[ i ] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[ i ] == u32 i);
let res = st.[ 12 ] <- st.[ 12 ] +| c in
let res1 = st1.[ 12 ] <- st1.[ 12 ] +. u32 i in
eq_intro (transpose_state res).[ i ] res1;
assert ((transpose_state res).[ i ] == res1);
assert (res1.[ 12 ] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[ 12 ] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2 | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Prims.unit",
"Hacl.Spec.Chacha20.Equiv.chacha20_init_scalar_lemma",
"Spec.Chacha20.state",
"Spec.Chacha20.chacha20_init",
"Prims._assert",
"Prims.eq2",
"Prims.l_or",
"Lib.IntTypes.range_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.u32",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.int_t",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_disEquality",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Lib.IntTypes.add_mod",
"Lib.IntTypes.mk_int",
"Lib.Sequence.op_String_Assignment",
"Hacl.Spec.Chacha20.Vec.uint32xN",
"Lib.IntVector.op_Plus_Bar",
"Lib.IntTypes.uint_t",
"Lib.IntVector.vec_v",
"Lib.IntVector.vec_t",
"Lib.Sequence.createi",
"Lib.IntVector.vec_counter",
"Hacl.Spec.Chacha20.Vec.vec_load_i",
"Lib.Sequence.map",
"Hacl.Spec.Chacha20.Vec.setup1"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i)) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i)) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_init_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.chacha20_init
k
n
c0)).[ i ]
(Spec.Chacha20.chacha20_init k n (c0 + i))) | {
"end_col": 20,
"end_line": 336,
"start_col": 39,
"start_line": 313
} |
FStar.Pervasives.Lemma | val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
} | val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i = | false | null | true | let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[ i / blocksize ] in
let b_i = sub b ((i / blocksize) * blocksize) blocksize in
let block = sub b ((i / 4) * 4) 4 in
calc ( == ) {
Seq.index (xor_block (transpose k) b) i;
( == ) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^.
(Seq.index (vec_v (transpose k).[ j ]) (i % bs / 4))))
(i % 4);
( == ) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4))))
(i % 4);
};
calc ( == ) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
( == ) { (xor_block_scalar_lemma_i ki b_i (i % blocksize);
Math.Lemmas.modulo_modulo_lemma i 4 16) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i ((i % blocksize / 4) * 4) 4)) ^.
ki.[ i % blocksize / 4 ]))
(i % 4);
( == ) { (lemma_i_div_blocksize w i;
Seq.Properties.slice_slice b
((i / blocksize) * blocksize)
((i / blocksize) * blocksize + blocksize)
((i % blocksize / 4) * 4)
((i % blocksize / 4) * 4 + 4)) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^.
(Seq.index ki (i % blocksize / 4))))
(i % 4);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.blocks",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.index",
"Spec.Chacha20.xor_block",
"Prims.op_Modulus",
"Lib.ByteSequence.uint_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.op_Hat_Dot",
"Lib.ByteSequence.uint_from_bytes_le",
"Lib.IntTypes.uint32",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Lib.Sequence.sub",
"Lib.Sequence.op_String_Access",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.modulo_modulo_lemma",
"Hacl.Spec.Chacha20.Equiv.xor_block_scalar_lemma_i",
"Prims.squash",
"FStar.Seq.Properties.slice_slice",
"Prims.op_Addition",
"Hacl.Spec.Chacha20.Equiv.lemma_i_div_blocksize",
"Hacl.Spec.Chacha20.Vec.xor_block",
"Hacl.Spec.Chacha20.Vec.transpose",
"Lib.IntVector.vec_v",
"Hacl.Spec.Chacha20.Vec.uint32xN",
"Hacl.Spec.Chacha20.Equiv.xor_block_vec_lemma_i",
"Hacl.Spec.Chacha20.Equiv.transpose_lemma_i",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Multiply",
"Prims.l_Forall",
"Prims.l_or",
"Lib.Sequence.index",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Prims.int"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize]) | [] | Hacl.Spec.Chacha20.Equiv.xor_block_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.state w ->
b: Hacl.Spec.Chacha20.Vec.blocks w ->
i: Prims.nat{i < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let k_i =
(Hacl.Spec.Chacha20.Vec.transpose_state k).[ i / Hacl.Spec.Chacha20.Equiv.blocksize ]
in
let b_i =
Lib.Sequence.sub b
((i / Hacl.Spec.Chacha20.Equiv.blocksize) * Hacl.Spec.Chacha20.Equiv.blocksize)
Hacl.Spec.Chacha20.Equiv.blocksize
in
(Hacl.Spec.Chacha20.Vec.xor_block (Hacl.Spec.Chacha20.Vec.transpose k) b).[ i ] ==
(Spec.Chacha20.xor_block k_i b_i).[ i % Hacl.Spec.Chacha20.Equiv.blocksize ])) | {
"end_col": 5,
"end_line": 477,
"start_col": 32,
"start_line": 454
} |
FStar.Pervasives.Lemma | val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j | val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j = | false | null | true | encrypt_block_lemma_bs_i #w k n c0 i b_v j | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Lib.IntTypes.size_nat",
"FStar.Mul.op_Star",
"Prims.op_LessThan",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_bs_i",
"Prims.unit"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_multi_vec_equiv_pre_k | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
hi_fv: Prims.nat ->
hi_f: Lib.IntTypes.size_nat{w * hi_fv <= hi_f} ->
i: Prims.nat{i < hi_fv} ->
b_v: Lib.Sequence.lseq Lib.IntTypes.uint8 (w * Hacl.Spec.Chacha20.Equiv.blocksize) ->
j: Prims.nat{j < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in
let st0 = Spec.Chacha20.chacha20_init k n c0 in
let f_v = Hacl.Spec.Chacha20.Vec.chacha20_encrypt_block st_v0 in
let f = Spec.Chacha20.chacha20_encrypt_block st0 in
Lib.Vec.Lemmas.map_blocks_multi_vec_equiv_pre_k w
Hacl.Spec.Chacha20.Equiv.blocksize
hi_fv
hi_f
f
f_v
i
b_v
j)) | {
"end_col": 44,
"end_line": 569,
"start_col": 2,
"start_line": 569
} |
FStar.Pervasives.Lemma | val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_block_s #uint8 #rem blocksize b_v j in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_block_lemma w blocksize (u8 0) rem b_v j }
Seq.index (f (w * hi_fv + j / blocksize) b1) (j % blocksize);
} | val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j = | false | null | true | let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_block_s #uint8 #rem blocksize b_v j in
calc ( == ) {
Seq.index (g_v hi_fv rem b_v) j;
( == ) { (encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j;
div_mul_lt blocksize j w) }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
( == ) { update_sub_get_block_lemma w blocksize (u8 0) rem b_v j }
Seq.index (f (w * hi_fv + j / blocksize) b1) (j % blocksize);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.size_nat",
"FStar.Mul.op_Star",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Prims.op_Division",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.Sequence.div_mul_lt",
"Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_bs_i",
"Prims.squash",
"Hacl.Spec.Chacha20.Equiv.update_sub_get_block_lemma",
"Lib.IntTypes.u8",
"Lib.IntTypes.int_t",
"Lib.Sequence.Lemmas.get_block_s",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.l_and",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.l_or",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_imp",
"Lib.Sequence.create",
"Prims.int",
"Spec.Chacha20.counter",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Chacha20.size_block",
"Spec.Chacha20.chacha20_encrypt_last",
"Spec.Chacha20.block",
"Spec.Chacha20.chacha20_encrypt_block",
"Prims.op_Multiply",
"Hacl.Spec.Chacha20.Vec.size_block",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last",
"Spec.Chacha20.state",
"Spec.Chacha20.chacha20_init",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.chacha20_init"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else ()
val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
//assert (j / blocksize < w);
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert (j / blocksize * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert (j / blocksize * blocksize + k == len / blocksize * blocksize + k);
calc (==) {
//Seq.index b k;
//(==) { }
Seq.index (Seq.slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain_v (j / blocksize * blocksize + k);
(==) { }
Seq.index plain_v (len / blocksize * blocksize + k);
}
val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain)
let update_sub_get_last_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
let aux (k:nat{k < blocksize}) : Lemma (Seq.index b k == Seq.index plain k) =
update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k;
update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k in
Classical.forall_intro aux;
eq_intro b plain
#set-options "--using_facts_from '* -FStar.Seq.Properties.slice_slice'"
val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k0 | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
hi_fv: Lib.IntTypes.size_nat{w * hi_fv + w <= Lib.IntTypes.max_size_t} ->
rem: Prims.nat{rem < w * Hacl.Spec.Chacha20.Equiv.blocksize} ->
b_v: Lib.Sequence.lseq Lib.IntTypes.uint8 rem ->
j:
Prims.nat{j < (rem / Hacl.Spec.Chacha20.Equiv.blocksize) * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in
let st0 = Spec.Chacha20.chacha20_init k n c0 in
let g_v = Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last st_v0 in
let f = Spec.Chacha20.chacha20_encrypt_block st0 in
let g = Spec.Chacha20.chacha20_encrypt_last st0 in
Lib.Vec.Lemmas.map_blocks_vec_equiv_pre_k w
Hacl.Spec.Chacha20.Equiv.blocksize
hi_fv
f
g
g_v
rem
b_v
j)) | {
"end_col": 5,
"end_line": 851,
"start_col": 68,
"start_line": 830
} |
FStar.Pervasives.Lemma | val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize) | val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j = | false | null | true | let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize) | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"FStar.Mul.op_Star",
"Hacl.Spec.Chacha20.Vec.blocks",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Hacl.Spec.Chacha20.Equiv.encrypt_block_scalar_lemma_i",
"Prims.op_Division",
"Prims.unit",
"Lib.Sequence.div_mul_lt",
"Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_st0_i",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.Lemmas.get_block_s",
"Lib.IntTypes.uint8",
"FStar.Math.Lemmas.cancel_mul_div",
"Spec.Chacha20.state",
"Spec.Chacha20.chacha20_init",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.chacha20_init"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize]) | [] | Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_bs_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
c: Hacl.Spec.Chacha20.Vec.counter{w * c <= Lib.IntTypes.max_size_t} ->
b_v: Hacl.Spec.Chacha20.Vec.blocks w ->
j: Prims.nat{j < w * Hacl.Spec.Chacha20.Equiv.blocksize}
-> FStar.Pervasives.Lemma
(ensures
(let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in
let st0 = Spec.Chacha20.chacha20_init k n c0 in
[@@ FStar.Pervasives.inline_let ]let _ =
FStar.Math.Lemmas.cancel_mul_div w Hacl.Spec.Chacha20.Equiv.blocksize
in
let b = Lib.Sequence.Lemmas.get_block_s Hacl.Spec.Chacha20.Equiv.blocksize b_v j in
[@@ FStar.Pervasives.inline_let ]let _ =
Lib.Sequence.div_mul_lt Hacl.Spec.Chacha20.Equiv.blocksize j w
in
(Hacl.Spec.Chacha20.Vec.chacha20_encrypt_block st_v0 c b_v).[ j ] ==
(Spec.Chacha20.chacha20_encrypt_block st0 (w * c + j / Hacl.Spec.Chacha20.Equiv.blocksize) b
).[ j % Hacl.Spec.Chacha20.Equiv.blocksize ])) | {
"end_col": 60,
"end_line": 548,
"start_col": 48,
"start_line": 541
} |
FStar.Pervasives.Lemma | val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_last_s #uint8 #rem blocksize b_v in
let plain = create blocksize (u8 0) in
let plain = update_sub plain 0 (rem % blocksize) b1 in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_last_lemma w blocksize (u8 0) rem b_v j; mod_div_lt blocksize j rem }
Seq.index (f (w * hi_fv + j / blocksize) plain) (j % blocksize);
(==) { }
Seq.index (g (w * hi_fv + j / blocksize) (rem % blocksize) b1) (j % blocksize);
} | val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k1 #w k n c0 hi_fv rem b_v j = | false | null | true | let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_last_s #uint8 #rem blocksize b_v in
let plain = create blocksize (u8 0) in
let plain = update_sub plain 0 (rem % blocksize) b1 in
calc ( == ) {
Seq.index (g_v hi_fv rem b_v) j;
( == ) { (encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j;
div_mul_lt blocksize j w) }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
( == ) { (update_sub_get_last_lemma w blocksize (u8 0) rem b_v j;
mod_div_lt blocksize j rem) }
Seq.index (f (w * hi_fv + j / blocksize) plain) (j % blocksize);
( == ) { () }
Seq.index (g (w * hi_fv + j / blocksize) (rem % blocksize) b1) (j % blocksize);
} | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.key",
"Hacl.Spec.Chacha20.Vec.nonce",
"Hacl.Spec.Chacha20.Vec.counter",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.size_nat",
"FStar.Mul.op_Star",
"Prims.nat",
"Prims.op_LessThan",
"Hacl.Spec.Chacha20.Equiv.blocksize",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Prims.l_and",
"Prims.op_Division",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.Sequence.div_mul_lt",
"Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_bs_i",
"Prims.squash",
"Lib.Sequence.mod_div_lt",
"Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma",
"Lib.IntTypes.u8",
"Lib.IntTypes.int_t",
"Lib.Sequence.sub",
"Prims.l_Forall",
"Prims.l_or",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Lib.IntTypes.mk_int",
"Prims.l_imp",
"Lib.Sequence.create",
"Lib.Sequence.Lemmas.get_last_s",
"Lib.Sequence.Lemmas.get_block_s",
"FStar.Math.Lemmas.cancel_mul_div",
"Prims.int",
"Spec.Chacha20.counter",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Chacha20.size_block",
"Spec.Chacha20.chacha20_encrypt_last",
"Spec.Chacha20.block",
"Spec.Chacha20.chacha20_encrypt_block",
"Prims.op_Multiply",
"Hacl.Spec.Chacha20.Vec.size_block",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last",
"Hacl.Spec.Chacha20.Vec.blocks",
"Hacl.Spec.Chacha20.Vec.chacha20_encrypt_block",
"Spec.Chacha20.state",
"Spec.Chacha20.chacha20_init",
"Hacl.Spec.Chacha20.Vec.state",
"Hacl.Spec.Chacha20.Vec.chacha20_init"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s
val quarter_round_lemma_i:
#w:lanes
-> a:idx -> b:idx -> c:idx -> d:idx
-> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal`
Scalar.quarter_round a b c d (transpose_state m).[i])
let quarter_round_lemma_i #w a b c d m i =
let lp0 = line a b d (size 16) m in
let lp1 = line c d b (size 12) lp0 in
let lp2 = line a b d (size 8) lp1 in
let lp3 = line c d b (size 7) lp2 in
assert (quarter_round #w a b c d m == lp3);
line_lemma_i a b d (size 16) m i;
line_lemma_i c d b (size 12) lp0 i;
line_lemma_i a b d (size 8) lp1 i;
line_lemma_i c d b (size 7) lp2 i;
eq_intro (transpose_state (quarter_round #w a b c d m)).[i]
(Scalar.quarter_round a b c d (transpose_state m).[i])
val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i])
let column_round_lemma_i #w m i =
let lp0 = quarter_round 0 4 8 12 m in
let lp1 = quarter_round 1 5 9 13 lp0 in
let lp2 = quarter_round 2 6 10 14 lp1 in
let lp3 = quarter_round 3 7 11 15 lp2 in
assert (column_round #w m == lp3);
quarter_round_lemma_i 0 4 8 12 m i;
quarter_round_lemma_i 1 5 9 13 lp0 i;
quarter_round_lemma_i 2 6 10 14 lp1 i;
quarter_round_lemma_i 3 7 11 15 lp2 i;
eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i])
val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i])
let diagonal_round_lemma_i #w m i =
let lp0 = quarter_round 0 5 10 15 m in
let lp1 = quarter_round 1 6 11 12 lp0 in
let lp2 = quarter_round 2 7 8 13 lp1 in
let lp3 = quarter_round 3 4 9 14 lp2 in
assert (diagonal_round #w m == lp3);
quarter_round_lemma_i 0 5 10 15 m i;
quarter_round_lemma_i 1 6 11 12 lp0 i;
quarter_round_lemma_i 2 7 8 13 lp1 i;
quarter_round_lemma_i 3 4 9 14 lp2 i;
eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i])
val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i])
let double_round_lemma_i #w m i =
let m1 = column_round m in
let m2 = diagonal_round m1 in
column_round_lemma_i m i;
diagonal_round_lemma_i m1 i
noextract
let scalar_rounds (m:Scalar.state) : Scalar.state =
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round (
Scalar.double_round (Scalar.double_round m)))))))))
val scalar_rounds_unroll_lemma: m:Scalar.state ->
Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m)
let scalar_rounds_unroll_lemma m =
let open Lib.LoopCombinators in
eq_repeat0 Scalar.double_round m;
unfold_repeat 10 Scalar.double_round m 0;
unfold_repeat 10 Scalar.double_round m 1;
unfold_repeat 10 Scalar.double_round m 2;
unfold_repeat 10 Scalar.double_round m 3;
unfold_repeat 10 Scalar.double_round m 4;
unfold_repeat 10 Scalar.double_round m 5;
unfold_repeat 10 Scalar.double_round m 6;
unfold_repeat 10 Scalar.double_round m 7;
unfold_repeat 10 Scalar.double_round m 8;
unfold_repeat 10 Scalar.double_round m 9
val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} ->
Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i])
let rounds_lemma_i #w m i =
let ms = (transpose_state m).[i] in
let m1 = double_round m in
let m2 = double_round m1 in
let m3 = double_round m2 in
let m4 = double_round m3 in
let m5 = double_round m4 in
let m6 = double_round m5 in
let m7 = double_round m6 in
let m8 = double_round m7 in
let m9 = double_round m8 in
let m10 = double_round m9 in
assert (rounds m == m10);
double_round_lemma_i #w m i;
double_round_lemma_i #w m1 i;
double_round_lemma_i #w m2 i;
double_round_lemma_i #w m3 i;
double_round_lemma_i #w m4 i;
double_round_lemma_i #w m5 i;
double_round_lemma_i #w m6 i;
double_round_lemma_i #w m7 i;
double_round_lemma_i #w m8 i;
double_round_lemma_i #w m9 i;
assert ((transpose_state m10).[i] == scalar_rounds ms);
scalar_rounds_unroll_lemma ms
val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} ->
Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
let sum_state_lemma_i #w st1 st2 i =
eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i])
val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
let add_counter_lemma_i #w st c i =
Math.Lemmas.modulo_lemma (w * c) (pow2 32);
assert (v (u32 w *! u32 c) == v (u32 (w * c)));
eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c))
//kb_v_i
val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i])
let chacha20_core_lemma_i #w c st_v0 i =
let k0 = add_counter c st_v0 in
add_counter_lemma_i st_v0 c i;
let k1 = rounds k0 in
rounds_lemma_i k0 i;
let k2 = sum_state k1 st_v0 in
sum_state_lemma_i k1 st_v0 i;
let k3 = add_counter c k2 in
add_counter_lemma_i k2 c i
//init_v_i
val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} ->
Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i))
let chacha20_init_lemma_i #w k n c0 i =
let st1 = setup1 k n c0 in
assert (st1 == Scalar.chacha20_init k n c0);
assert (st1.[12] == u32 c0);
let st = map (vec_load_i w) st1 in
eq_intro (transpose_state st).[i] st1;
assert ((transpose_state st).[i] == st1);
let c = vec_counter U32 w in
assert ((vec_v c).[i] == u32 i);
let res = st.[12] <- st.[12] +| c in
let res1 = st1.[12] <- st1.[12] +. u32 i in
eq_intro (transpose_state res).[i] res1;
assert ((transpose_state res).[i] == res1);
assert (res1.[12] == u32 c0 +. u32 i);
assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i)));
assert (res1.[12] == u32 (c0 + i));
let res2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
eq_intro res1 res2
///
/// XOR-related lemmas
///
val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} ->
Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4)
let lemma_i_div_w4 w i =
let bs = w * 4 in
calc (==) {
i / bs * bs + i % bs / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 }
i / bs * bs + i % bs - i % bs % 4;
(==) { Math.Lemmas.euclidean_division_definition i bs }
i - i % bs % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} ->
Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4)
let lemma_i_div_blocksize w i =
calc (==) {
i / blocksize * blocksize + i % blocksize / 4 * 4;
(==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 }
i / blocksize * blocksize + i % blocksize - i % blocksize % 4;
(==) { Math.Lemmas.modulo_modulo_lemma i 4 16 }
i / blocksize * blocksize + i % blocksize - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i blocksize }
i - i % 4;
(==) { Math.Lemmas.euclidean_division_definition i 4 }
i / 4 * 4;
}
val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let bs = w * 4 in
let j = i / bs in
let block = sub b (i / 4 * 4) 4 in
Seq.index (xor_block k b) i ==
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4))
let xor_block_vec_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let kb_j = vec_v k.[j] in
let b_j = sub b (i / bs * bs) bs in
let b_i = sub b_j (i % bs / 4 * 4) 4 in
let block = sub b (i / 4 * 4) 4 in
let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in
calc (==) {
Seq.index (xor_block k b) i;
(==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i }
Seq.index (uints_to_bytes_le ob) (i % bs);
(==) { index_uints_to_bytes_le ob (i % bs) }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4);
(==) { Math.Lemmas.modulo_modulo_lemma i 4 w }
Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4);
(==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4);
}
val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma
((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4])
let xor_block_scalar_lemma_i k b i =
let ib = uints_from_bytes_le b in
let ob = map2 (^.) ib k in
let b_i = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (uints_to_bytes_le ob) i;
(==) { index_uints_to_bytes_le ob i }
Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4);
(==) { (* def of xor *) }
Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4);
(==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4);
}
val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma
(Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) ==
Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4))
let transpose_lemma_i #w k i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
calc (==) {
Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4);
(==) { Math.Lemmas.modulo_division_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w);
(==) { Math.Lemmas.division_multiplication_lemma i 4 w }
Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w);
(==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 }
Seq.index ki (i / 4 % 16);
(==) { Math.Lemmas.modulo_division_lemma i 4 16 }
Seq.index ki (i % blocksize / 4);
}
val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma
(let k_i = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
(xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize])
let xor_block_lemma_i #w k b i =
let bs = w * 4 in
let j = i / bs in
let ki = (transpose_state k).[i / blocksize] in
let b_i = sub b (i / blocksize * blocksize) blocksize in
let block = sub b (i / 4 * 4) 4 in
calc (==) {
Seq.index (xor_block (transpose k) b) i;
(==) { xor_block_vec_lemma_i #w (transpose k) b i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4);
(==) { transpose_lemma_i #w k i }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
};
calc (==) {
Seq.index (Scalar.xor_block ki b_i) (i % blocksize);
(==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4);
(==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize)
(i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) }
Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4);
}
///
/// map_blocks_vec
///
val encrypt_block_scalar_lemma_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> b_i:Scalar.block
-> i:nat{i < w} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal`
Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i)
let encrypt_block_scalar_lemma_i #w k n c0 c b i =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
chacha20_init_lemma_i #w k n c0 i;
assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i));
kb_equiv_lemma #w k n c0 c i
val encrypt_block_lemma_st0_i:
#w:lanes
-> st_v0:state w
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize])
let encrypt_block_lemma_st0_i #w st_v0 c b_v j =
let k = chacha20_core c st_v0 in
chacha20_core_lemma_i #w c st_v0 (j / blocksize);
xor_block_lemma_i #w k b_v j
val encrypt_block_lemma_bs_i:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> c:counter{w * c <= max_size_t}
-> b_v:blocks w
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
div_mul_lt blocksize j w;
(chacha20_encrypt_block st_v0 c b_v).[j] ==
(Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize])
let encrypt_block_lemma_bs_i #w k n c0 c b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in
encrypt_block_lemma_st0_i #w st_v0 c b_v j;
div_mul_lt blocksize j w;
encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize)
val chacha20_map_blocks_multi_vec_equiv_pre_k:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:nat // n == hi_fv == len / (w * blocksize)
-> hi_f:size_nat{w * hi_fv <= hi_f}
-> i:nat{i < hi_fv}
-> b_v:lseq uint8 (w * blocksize)
-> j:nat{j < w * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let f_v = chacha20_encrypt_block st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
////////////////////////
// Start of proof of VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j
////////////////////////
val update_sub_is_append:
#a:Type0
-> zero:a
-> blocksize:size_pos
-> len:nat{len < blocksize}
-> b_v:lseq a len ->
Lemma
(let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
plain == Seq.append b_v zeros)
let update_sub_is_append #a zero blocksize len b_v =
let plain = create blocksize zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize - len) zero in
Seq.Properties.lemma_split plain len;
Seq.Properties.lemma_split (Seq.append b_v zeros) len;
eq_intro plain (Seq.append b_v zeros)
val update_sub_get_block_lemma_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
Seq.index (SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j) k ==
Seq.index (SeqLemmas.get_block_s #a #len blocksize b_v j) k)
let update_sub_get_block_lemma_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
let zeros = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain == Seq.append b_v zeros);
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
//assert (j / blocksize < w);
//assert (j < blocksize_v / blocksize * blocksize);
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
calc (<=) {
(j / blocksize + 1) * blocksize;
(<=) { div_mul_lt blocksize j (len / blocksize) }
len / blocksize * blocksize;
(<=) { Math.Lemmas.multiply_fractions len blocksize }
len;
};
calc (==) {
Seq.index b_p k;
(==) { }
Seq.index (Seq.slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain (j / blocksize * blocksize + k);
(==) { Seq.lemma_index_app1 b_v zeros (j / blocksize * blocksize + k) }
Seq.index b_v (j / blocksize * blocksize + k);
};
Seq.lemma_index_slice b_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k
val update_sub_get_block_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{j < len / blocksize * blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j ==
SeqLemmas.get_block_s #a #len blocksize b_v j)
let update_sub_get_block_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain = create blocksize_v zero in
let plain = update_sub plain 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b_p = SeqLemmas.get_block_s #a #blocksize_v blocksize plain j in
let b = SeqLemmas.get_block_s #a #len blocksize b_v j in
Classical.forall_intro (update_sub_get_block_lemma_k #a w blocksize zero len b_v j);
eq_intro b b_p
val update_sub_get_last_lemma_plain_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
Seq.index plain k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k =
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let zeros = create (blocksize - len % blocksize) zero in
update_sub_is_append #a zero blocksize (len % blocksize) block_l;
assert (plain == Seq.append block_l zeros);
if k < len % blocksize then begin
calc (==) {
Seq.index plain k;
(==) { Seq.lemma_index_app1 block_l zeros k }
Seq.index block_l k;
(==) { Seq.lemma_index_slice b_v (len - len % blocksize) len k }
Seq.index b_v (len - len % blocksize + k);
(==) { Math.Lemmas.euclidean_division_definition len blocksize }
Seq.index b_v (len / blocksize * blocksize + k);
} end
else ()
val update_sub_get_last_lemma_plain_v_k:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len}
-> k:nat{k < blocksize} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
div_interval blocksize (len / blocksize) j;
Seq.index b k == (if k < len % blocksize then Seq.index b_v (len / blocksize * blocksize + k) else zero))
let update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
let zeros_v = create (blocksize_v - len) zero in
update_sub_is_append #a zero blocksize_v len b_v;
assert (plain_v == Seq.append b_v zeros_v);
div_mul_lt blocksize j w;
//assert (j / blocksize < w);
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
Math.Lemmas.lemma_mult_le_right blocksize (j / blocksize + 1) w;
assert (j / blocksize * blocksize + blocksize <= blocksize_v);
div_interval blocksize (len / blocksize) j;
assert (j / blocksize * blocksize + k == len / blocksize * blocksize + k);
calc (==) {
//Seq.index b k;
//(==) { }
Seq.index (Seq.slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize)) k;
(==) { Seq.lemma_index_slice plain_v (j / blocksize * blocksize) (j / blocksize * blocksize + blocksize) k }
Seq.index plain_v (j / blocksize * blocksize + k);
(==) { }
Seq.index plain_v (len / blocksize * blocksize + k);
}
val update_sub_get_last_lemma:
#a:Type
-> w:size_pos
-> blocksize:size_pos{w * blocksize <= max_size_t}
-> zero:a
-> len:nat{len < w * blocksize}
-> b_v:lseq a len
-> j:nat{len / blocksize * blocksize <= j /\ j < len} ->
Lemma
(let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j == plain)
let update_sub_get_last_lemma #a w blocksize zero len b_v j =
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v zero in
let plain_v = update_sub plain_v 0 len b_v in
div_mul_lt blocksize j w;
Math.Lemmas.cancel_mul_div w blocksize;
let block_l = SeqLemmas.get_last_s #a #len blocksize b_v in
let plain = create blocksize zero in
let plain = update_sub plain 0 (len % blocksize) block_l in
let b = SeqLemmas.get_block_s #a #blocksize_v blocksize plain_v j in
let aux (k:nat{k < blocksize}) : Lemma (Seq.index b k == Seq.index plain k) =
update_sub_get_last_lemma_plain_k #a w blocksize zero len b_v j k;
update_sub_get_last_lemma_plain_v_k #a w blocksize zero len b_v j k in
Classical.forall_intro aux;
eq_intro b plain
#set-options "--using_facts_from '* -FStar.Seq.Properties.slice_slice'"
val chacha20_map_blocks_vec_equiv_pre_k0:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{j < rem / blocksize * blocksize} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j)
let chacha20_map_blocks_vec_equiv_pre_k0 #w k n c0 hi_fv rem b_v j =
let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
let blocksize_v = w * blocksize in
let plain_v = create blocksize_v (u8 0) in
let plain_v = update_sub plain_v 0 rem b_v in
Math.Lemmas.cancel_mul_div w blocksize;
let b = SeqLemmas.get_block_s #uint8 #blocksize_v blocksize plain_v j in
let b1 = SeqLemmas.get_block_s #uint8 #rem blocksize b_v j in
calc (==) {
Seq.index (g_v hi_fv rem b_v) j;
(==) { encrypt_block_lemma_bs_i #w k n c0 hi_fv plain_v j; div_mul_lt blocksize j w }
Seq.index (f (w * hi_fv + j / blocksize) b) (j % blocksize);
(==) { update_sub_get_block_lemma w blocksize (u8 0) rem b_v j }
Seq.index (f (w * hi_fv + j / blocksize) b1) (j % blocksize);
}
val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val chacha20_map_blocks_vec_equiv_pre_k1:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter{c0 + w <= max_size_t}
-> hi_fv:size_nat{w * hi_fv + w <= max_size_t} // n == hi_fv == len / (w * blocksize)
-> rem:nat{rem < w * blocksize}
-> b_v:lseq uint8 rem
-> j:nat{rem / blocksize * blocksize <= j /\ j < rem} ->
Lemma
(let st_v0 = chacha20_init #w k n c0 in
let st0 = Scalar.chacha20_init k n c0 in
let g_v = chacha20_encrypt_last st_v0 in
let f = Scalar.chacha20_encrypt_block st0 in
let g = Scalar.chacha20_encrypt_last st0 in
VecLemmas.map_blocks_vec_equiv_pre_k w blocksize hi_fv f g g_v rem b_v j) | [] | Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k1 | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Spec.Chacha20.Vec.key ->
n: Hacl.Spec.Chacha20.Vec.nonce ->
c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} ->
hi_fv: Lib.IntTypes.size_nat{w * hi_fv + w <= Lib.IntTypes.max_size_t} ->
rem: Prims.nat{rem < w * Hacl.Spec.Chacha20.Equiv.blocksize} ->
b_v: Lib.Sequence.lseq Lib.IntTypes.uint8 rem ->
j:
Prims.nat
{ (rem / Hacl.Spec.Chacha20.Equiv.blocksize) * Hacl.Spec.Chacha20.Equiv.blocksize <= j /\
j < rem }
-> FStar.Pervasives.Lemma
(ensures
(let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in
let st0 = Spec.Chacha20.chacha20_init k n c0 in
let g_v = Hacl.Spec.Chacha20.Vec.chacha20_encrypt_last st_v0 in
let f = Spec.Chacha20.chacha20_encrypt_block st0 in
let g = Spec.Chacha20.chacha20_encrypt_last st0 in
Lib.Vec.Lemmas.map_blocks_vec_equiv_pre_k w
Hacl.Spec.Chacha20.Equiv.blocksize
hi_fv
f
g
g_v
rem
b_v
j)) | {
"end_col": 5,
"end_line": 898,
"start_col": 68,
"start_line": 871
} |
FStar.Pervasives.Lemma | val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i]) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20.Vec",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence.Lemmas",
"short_module": "SeqLemmas"
},
{
"abbrev": true,
"full_module": "Lib.Vec.Lemmas",
"short_module": "VecLemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Chacha20.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Scalar"
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let line_lemma_i #w a b d s m0 i =
let m0_s = (transpose_state #w m0).[i] in
let m1 = m0.[a] <- m0.[a] +| m0.[b] in
let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in
eq_intro (transpose_state m1).[i] m1_s;
let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in
let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in
eq_intro (transpose_state m2).[i] m2_s | val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i])
let line_lemma_i #w a b d s m0 i = | false | null | true | let m0_s = (transpose_state #w m0).[ i ] in
let m1 = m0.[ a ] <- m0.[ a ] +| m0.[ b ] in
let m1_s = m0_s.[ a ] <- m0_s.[ a ] +. m0_s.[ b ] in
eq_intro (transpose_state m1).[ i ] m1_s;
let m2 = m1.[ d ] <- (m1.[ d ] ^| m1.[ a ]) <<<| s in
let m2_s = m1_s.[ d ] <- (m1_s.[ d ] ^. m1_s.[ a ]) <<<. s in
eq_intro (transpose_state m2).[ i ] m2_s | {
"checked_file": "Hacl.Spec.Chacha20.Equiv.fst.checked",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Vec.Lemmas.fsti.checked",
"Lib.Sequence.Lemmas.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Chacha20.Vec.fst.checked",
"Hacl.Spec.Chacha20.Lemmas.fst.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Chacha20.Equiv.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Chacha20.Vec.lanes",
"Hacl.Spec.Chacha20.Vec.idx",
"Lib.IntTypes.rotval",
"Lib.IntTypes.U32",
"Hacl.Spec.Chacha20.Vec.state",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint32",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.Chacha20.Vec.transpose_state",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.IntTypes.rotate_left",
"Lib.IntTypes.logxor",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_imp",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.op_Less_Less_Less_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Hacl.Spec.Chacha20.Vec.uint32xN",
"Lib.IntVector.op_Less_Less_Less_Bar",
"Lib.IntVector.op_Hat_Bar",
"Prims.unit",
"Lib.IntTypes.add_mod",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntVector.op_Plus_Bar"
] | [] | module Hacl.Spec.Chacha20.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.IntVector
module Scalar = Spec.Chacha20
module Lemmas = Hacl.Spec.Chacha20.Lemmas
module VecLemmas = Lib.Vec.Lemmas
module SeqLemmas = Lib.Sequence.Lemmas
open Hacl.Spec.Chacha20.Vec
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let blocksize = size_block
///
/// Scalar-related lemmas
///
val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma
(let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un)
let chacha20_init_scalar_lemma k n c0 =
let uc = map secret chacha20_constants in
let uk = uints_from_bytes_le #U32 #SEC #8 k in
let uctr = create 1 (u32 c0) in
let un = uints_from_bytes_le #U32 #SEC #3 n in
let res = uc @| uk @| uctr @| un in
assert (res == concat uc (concat uk (concat uctr un)));
eq_intro res (concat (concat (concat uc uk) uctr) un);
let len0 = 4 in
let len1 = 8 in
let len2 = 1 in
let len3 = 3 in
let res = concat (concat (concat uc uk) uctr) un in
let st = create 16 (u32 0) in
let st = update_sub st 0 4 (map secret chacha20_constants) in
let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in
eq_intro (sub st 0 4) uc;
let st = st.[12] <- u32 c0 in
eq_intro (sub st 0 4) uc;
eq_intro (sub st 4 8) uk;
let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in
eq_intro (sub res1 0 4) uc;
eq_intro (sub res1 4 8) uk;
eq_intro (sub res1 12 1) uctr;
eq_intro (sub res1 13 3) un;
Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0;
Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1);
Seq.Properties.lemma_split res (len0 + len1 + len2);
Seq.Properties.lemma_split res1 (len0 + len1 + len2)
val add_counter_lemma_aux:
w:lanes
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w}
-> b:uint32 ->
Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c))
let add_counter_lemma_aux w c0 c i b =
let lp = b +. u32 c0 +. u32 (w * c + i) in
let rp = b +. u32 (c0 + i) +. u32 (w * c) in
assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32);
assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32);
Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32)
val chacha20_core_scalar_lemma:
w:lanes
-> st1:Scalar.state
-> st2:Scalar.state
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(requires
(forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\
st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i)))
(ensures
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let chacha20_core_scalar_lemma w st1 st2 c0 c i =
let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in
assert (k1.[12] == u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter st2 (w * c) in
assert (k2.[12] == u32 (c0 + i) +. u32 (w * c));
assert (v k1.[12] == v k2.[12]);
eq_intro k1 k2;
let k = Scalar.rounds k1 in
let k1 = Scalar.sum_state k st1 in
assert (k1.[12] == k.[12] +. u32 c0);
let k2 = Scalar.sum_state k st2 in
assert (k2.[12] == k.[12] +. u32 (c0 + i));
assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]);
let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in
assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i));
let k2 = Scalar.chacha20_add_counter k2 (w * c) in
assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c));
add_counter_lemma_aux w c0 c i k.[12];
eq_intro k1 k2
val kb_equiv_lemma:
#w:lanes
-> k:key
-> n:nonce
-> c0:counter
-> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t}
-> i:nat{i < w} -> Lemma
(let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2)
let kb_equiv_lemma #w k n c0 c i =
let st1 = Scalar.chacha20_init k n c0 in
let st2 = Scalar.chacha20_init k n (c0 + i) in
chacha20_init_scalar_lemma k n c0;
chacha20_init_scalar_lemma k n (c0 + i);
chacha20_core_scalar_lemma w st1 st2 c0 c i
///
/// Vectorised-related lemmas
///
val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i]) | false | false | Hacl.Spec.Chacha20.Equiv.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val line_lemma_i:
#w:lanes
-> a:idx -> b:idx -> d:idx
-> s:rotval U32 -> m:state w
-> i:nat{i < w} ->
Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i]) | [] | Hacl.Spec.Chacha20.Equiv.line_lemma_i | {
"file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Chacha20.Vec.idx ->
b: Hacl.Spec.Chacha20.Vec.idx ->
d: Hacl.Spec.Chacha20.Vec.idx ->
s: Lib.IntTypes.rotval Lib.IntTypes.U32 ->
m: Hacl.Spec.Chacha20.Vec.state w ->
i: Prims.nat{i < w}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Vec.transpose_state (Hacl.Spec.Chacha20.Vec.line a
b
d
s
m)).[ i ]
(Spec.Chacha20.line a b d s (Hacl.Spec.Chacha20.Vec.transpose_state m).[ i ])) | {
"end_col": 40,
"end_line": 156,
"start_col": 34,
"start_line": 149
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) | let t64_no_mod = | false | null | false | TD_Buffer TUInt64 TUInt64 ({ modified = false; strict_disjointness = false; taint = MS.Secret }) | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Interop.Base.TD_Buffer",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.Interop.Base.Mkbuffer_qualifiers",
"Vale.Arch.HeapTypes_s.Secret"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val t64_no_mod : Vale.Interop.Base.td | [] | Vale.Stdcalls.X64.Fmul.t64_no_mod | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Interop.Base.td | {
"end_col": 105,
"end_line": 43,
"start_col": 17,
"start_line": 43
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let code_Fmul1 = FH.va_code_Fmul1_stdcall IA.win | let code_Fmul1 = | false | null | false | FH.va_code_Fmul1_stdcall IA.win | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Curve25519.X64.FastHybrid.va_code_Fmul1_stdcall",
"Vale.Interop.Assumptions.win"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul_lemma' has the required type *)
noextract
let fmul_lemma = as_t #(VSig.vale_sig_stdcall fmul_pre fmul_post) fmul_lemma'
noextract
let code_Fmul = FW.va_code_Fmul_stdcall IA.win
(* Here's the type expected for the fmul wrapper *)
[@__reduce__] noextract
let lowstar_fmul_t =
assert_norm (List.length fmul_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fmul
fmul_dom
[]
_
_
(W.mk_prediction code_Fmul fmul_dom [] (fmul_lemma code_Fmul IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul2_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul2_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul2_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul2_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul2_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul2_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul2_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul2_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul2_lemma' has the required type *)
noextract
let fmul2_lemma = as_t #(VSig.vale_sig_stdcall fmul2_pre fmul2_post) fmul2_lemma'
noextract
let code_Fmul2 = FW.va_code_Fmul2_stdcall IA.win
(* Here's the type expected for the fmul wrapper *)
[@__reduce__] noextract
let lowstar_fmul2_t =
assert_norm (List.length fmul_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fmul2
fmul_dom
[]
_
_
(W.mk_prediction code_Fmul2 fmul_dom [] (fmul2_lemma code_Fmul2 IA.win))
[@__reduce__] noextract
let fmul1_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; tuint64] in
assert_norm (List.length y = 3);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul1_pre : VSig.vale_pre fmul1_dom =
fun (c:V.va_code)
(out:b64)
(f1:b64)
(f2:uint64)
(va_s0:V.va_state) ->
FH.va_req_Fmul1_stdcall c va_s0 IA.win
(as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2)
[@__reduce__] noextract
let fmul1_post : VSig.vale_post fmul1_dom =
fun (c:V.va_code)
(out:b64)
(f1:b64)
(f2:uint64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FH.va_ens_Fmul1_stdcall c va_s0 IA.win (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let fmul1_lemma'
(code:V.va_code)
(_win:bool)
(out:b64)
(f1:b64)
(f2:uint64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul1_pre code out f1 f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul1_post code out f1 f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
ME.loc_none) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FH.va_lemma_Fmul1_stdcall code va_s0 IA.win (as_vale_buffer out) (as_vale_buffer f1) (UInt64.v f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
let s0 = va_s0 in
let s1 = va_s1 in
let regs_modified = IX64.regs_modified_stdcall in
let xmms_modified = IX64.xmms_modified_stdcall in
let open MS in
let open Vale.AsLowStar.ValeSig in
assert (forall (r:MS.reg_64).{:pattern vale_save_reg r s0 s1} not (regs_modified r) ==> vale_save_reg r s0 s1);
assert (forall (x:MS.reg_xmm).{:pattern vale_save_xmm x s0 s1} not (xmms_modified x) ==> vale_save_xmm x s0 s1);
(va_s1, f)
(* Prove that fmul1_lemma' has the required type *)
noextract
let fmul1_lemma = as_t #(VSig.vale_sig_stdcall fmul1_pre fmul1_post) fmul1_lemma' | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val code_Fmul1 : Vale.X64.Decls.va_code | [] | Vale.Stdcalls.X64.Fmul.code_Fmul1 | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.X64.Decls.va_code | {
"end_col": 48,
"end_line": 280,
"start_col": 17,
"start_line": 280
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq | let t64_mod = | false | null | false | TD_Buffer TUInt64 TUInt64 default_bq | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Interop.Base.TD_Buffer",
"Vale.Arch.HeapTypes_s.TUInt64",
"Vale.Interop.Base.default_bq"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64 | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val t64_mod : Vale.Interop.Base.td | [] | Vale.Stdcalls.X64.Fmul.t64_mod | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Interop.Base.td | {
"end_col": 50,
"end_line": 41,
"start_col": 14,
"start_line": 41
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let b64 = buf_t TUInt64 TUInt64 | let b64 = | false | null | false | buf_t TUInt64 TUInt64 | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Interop.Base.buf_t",
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val b64 : Type0 | [] | Vale.Stdcalls.X64.Fmul.b64 | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 31,
"end_line": 39,
"start_col": 10,
"start_line": 39
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let tuint64 = TD_Base TUInt64 | let tuint64 = | false | null | false | TD_Base TUInt64 | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Interop.Base.TD_Base",
"Vale.Arch.HeapTypes_s.TUInt64"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret}) | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val tuint64 : Vale.Interop.Base.td | [] | Vale.Stdcalls.X64.Fmul.tuint64 | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Interop.Base.td | {
"end_col": 29,
"end_line": 45,
"start_col": 14,
"start_line": 45
} |
|
Prims.Tot | val fmul_pre:VSig.vale_pre fmul_dom | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) | val fmul_pre:VSig.vale_pre fmul_dom
let fmul_pre:VSig.vale_pre fmul_dom = | false | null | false | fun (c: V.va_code) (tmp: b64) (f1: b64) (out: b64) (f2: b64) (va_s0: V.va_state) ->
FW.va_req_Fmul_stdcall c
va_s0
IA.win
(as_vale_buffer tmp)
(as_vale_buffer f1)
(as_vale_buffer out)
(as_vale_buffer f2) | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.Fmul.b64",
"Vale.X64.Decls.va_state",
"Vale.Curve25519.X64.FastWide.va_req_Fmul_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.prop"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul_pre:VSig.vale_pre fmul_dom | [] | Vale.Stdcalls.X64.Fmul.fmul_pre | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.AsLowStar.ValeSig.vale_pre Vale.Stdcalls.X64.Fmul.fmul_dom | {
"end_col": 89,
"end_line": 63,
"start_col": 2,
"start_line": 56
} |
Prims.Tot | val fmul_post:VSig.vale_post fmul_dom | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f | val fmul_post:VSig.vale_post fmul_dom
let fmul_post:VSig.vale_post fmul_dom = | false | null | false | fun
(c: V.va_code)
(tmp: b64)
(f1: b64)
(out: b64)
(f2: b64)
(va_s0: V.va_state)
(va_s1: V.va_state)
(f: V.va_fuel)
->
FW.va_ens_Fmul_stdcall c
va_s0
IA.win
(as_vale_buffer tmp)
(as_vale_buffer f1)
(as_vale_buffer out)
(as_vale_buffer f2)
va_s1
f | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.Fmul.b64",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"Vale.Curve25519.X64.FastWide.va_ens_Fmul_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.prop"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul_post:VSig.vale_post fmul_dom | [] | Vale.Stdcalls.X64.Fmul.fmul_post | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.Fmul.fmul_dom | {
"end_col": 133,
"end_line": 75,
"start_col": 2,
"start_line": 67
} |
Prims.Tot | val fmul2_pre:VSig.vale_pre fmul_dom | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul2_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul2_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) | val fmul2_pre:VSig.vale_pre fmul_dom
let fmul2_pre:VSig.vale_pre fmul_dom = | false | null | false | fun (c: V.va_code) (tmp: b64) (f1: b64) (out: b64) (f2: b64) (va_s0: V.va_state) ->
FW.va_req_Fmul2_stdcall c
va_s0
IA.win
(as_vale_buffer tmp)
(as_vale_buffer f1)
(as_vale_buffer out)
(as_vale_buffer f2) | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.Fmul.b64",
"Vale.X64.Decls.va_state",
"Vale.Curve25519.X64.FastWide.va_req_Fmul2_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.prop"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul_lemma' has the required type *)
noextract
let fmul_lemma = as_t #(VSig.vale_sig_stdcall fmul_pre fmul_post) fmul_lemma'
noextract
let code_Fmul = FW.va_code_Fmul_stdcall IA.win
(* Here's the type expected for the fmul wrapper *)
[@__reduce__] noextract
let lowstar_fmul_t =
assert_norm (List.length fmul_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fmul
fmul_dom
[]
_
_
(W.mk_prediction code_Fmul fmul_dom [] (fmul_lemma code_Fmul IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul2_pre:VSig.vale_pre fmul_dom | [] | Vale.Stdcalls.X64.Fmul.fmul2_pre | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.AsLowStar.ValeSig.vale_pre Vale.Stdcalls.X64.Fmul.fmul_dom | {
"end_col": 89,
"end_line": 142,
"start_col": 2,
"start_line": 135
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let code_Fmul = FW.va_code_Fmul_stdcall IA.win | let code_Fmul = | false | null | false | FW.va_code_Fmul_stdcall IA.win | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Curve25519.X64.FastWide.va_code_Fmul_stdcall",
"Vale.Interop.Assumptions.win"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul_lemma' has the required type *)
noextract
let fmul_lemma = as_t #(VSig.vale_sig_stdcall fmul_pre fmul_post) fmul_lemma' | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val code_Fmul : Vale.X64.Decls.va_code | [] | Vale.Stdcalls.X64.Fmul.code_Fmul | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.X64.Decls.va_code | {
"end_col": 46,
"end_line": 118,
"start_col": 16,
"start_line": 118
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let uint64 = UInt64.t | let uint64 = | false | null | false | UInt64.t | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"FStar.UInt64.t"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val uint64 : Prims.eqtype | [] | Vale.Stdcalls.X64.Fmul.uint64 | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.eqtype | {
"end_col": 21,
"end_line": 30,
"start_col": 13,
"start_line": 30
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let code_Fmul2 = FW.va_code_Fmul2_stdcall IA.win | let code_Fmul2 = | false | null | false | FW.va_code_Fmul2_stdcall IA.win | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Curve25519.X64.FastWide.va_code_Fmul2_stdcall",
"Vale.Interop.Assumptions.win"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul_lemma' has the required type *)
noextract
let fmul_lemma = as_t #(VSig.vale_sig_stdcall fmul_pre fmul_post) fmul_lemma'
noextract
let code_Fmul = FW.va_code_Fmul_stdcall IA.win
(* Here's the type expected for the fmul wrapper *)
[@__reduce__] noextract
let lowstar_fmul_t =
assert_norm (List.length fmul_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fmul
fmul_dom
[]
_
_
(W.mk_prediction code_Fmul fmul_dom [] (fmul_lemma code_Fmul IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul2_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul2_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul2_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul2_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul2_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul2_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul2_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul2_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul2_lemma' has the required type *)
noextract
let fmul2_lemma = as_t #(VSig.vale_sig_stdcall fmul2_pre fmul2_post) fmul2_lemma' | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val code_Fmul2 : Vale.X64.Decls.va_code | [] | Vale.Stdcalls.X64.Fmul.code_Fmul2 | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.X64.Decls.va_code | {
"end_col": 48,
"end_line": 197,
"start_col": 17,
"start_line": 197
} |
|
Prims.Tot | val fmul2_post:VSig.vale_post fmul_dom | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul2_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul2_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f | val fmul2_post:VSig.vale_post fmul_dom
let fmul2_post:VSig.vale_post fmul_dom = | false | null | false | fun
(c: V.va_code)
(tmp: b64)
(f1: b64)
(out: b64)
(f2: b64)
(va_s0: V.va_state)
(va_s1: V.va_state)
(f: V.va_fuel)
->
FW.va_ens_Fmul2_stdcall c
va_s0
IA.win
(as_vale_buffer tmp)
(as_vale_buffer f1)
(as_vale_buffer out)
(as_vale_buffer f2)
va_s1
f | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.Fmul.b64",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"Vale.Curve25519.X64.FastWide.va_ens_Fmul2_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt64",
"Prims.prop"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul_lemma' has the required type *)
noextract
let fmul_lemma = as_t #(VSig.vale_sig_stdcall fmul_pre fmul_post) fmul_lemma'
noextract
let code_Fmul = FW.va_code_Fmul_stdcall IA.win
(* Here's the type expected for the fmul wrapper *)
[@__reduce__] noextract
let lowstar_fmul_t =
assert_norm (List.length fmul_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fmul
fmul_dom
[]
_
_
(W.mk_prediction code_Fmul fmul_dom [] (fmul_lemma code_Fmul IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul2_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul2_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul2_post:VSig.vale_post fmul_dom | [] | Vale.Stdcalls.X64.Fmul.fmul2_post | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.Fmul.fmul_dom | {
"end_col": 134,
"end_line": 154,
"start_col": 2,
"start_line": 146
} |
Prims.Tot | val as_t (#a: Type) (x: normal a) : a | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let as_t (#a:Type) (x:normal a) : a = x | val as_t (#a: Type) (x: normal a) : a
let as_t (#a: Type) (x: normal a) : a = | false | null | false | x | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Interop.Base.normal"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *) | false | false | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val as_t (#a: Type) (x: normal a) : a | [] | Vale.Stdcalls.X64.Fmul.as_t | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Vale.Interop.Base.normal a -> a | {
"end_col": 39,
"end_line": 34,
"start_col": 38,
"start_line": 34
} |
Prims.Tot | val as_normal_t (#a: Type) (x: a) : normal a | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let as_normal_t (#a:Type) (x:a) : normal a = x | val as_normal_t (#a: Type) (x: a) : normal a
let as_normal_t (#a: Type) (x: a) : normal a = | false | null | false | x | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Interop.Base.normal"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x | false | false | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val as_normal_t (#a: Type) (x: a) : normal a | [] | Vale.Stdcalls.X64.Fmul.as_normal_t | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: a -> Vale.Interop.Base.normal a | {
"end_col": 46,
"end_line": 36,
"start_col": 45,
"start_line": 36
} |
Prims.Tot | val fmul_dom:IX64.arity_ok_stdcall td | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y | val fmul_dom:IX64.arity_ok_stdcall td
let fmul_dom:IX64.arity_ok_stdcall td = | false | null | false | let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Vale.Interop.Base.td",
"Prims.list",
"Prims.Cons",
"Vale.Stdcalls.X64.Fmul.t64_mod",
"Vale.Stdcalls.X64.Fmul.t64_no_mod",
"Prims.Nil"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64 | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul_dom:IX64.arity_ok_stdcall td | [] | Vale.Stdcalls.X64.Fmul.fmul_dom | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Vale.Interop.X64.arity_ok_stdcall Vale.Interop.Base.td | {
"end_col": 3,
"end_line": 51,
"start_col": 40,
"start_line": 48
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lowstar_fmul_t =
assert_norm (List.length fmul_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fmul
fmul_dom
[]
_
_
(W.mk_prediction code_Fmul fmul_dom [] (fmul_lemma code_Fmul IA.win)) | let lowstar_fmul_t = | false | null | false | assert_norm (List.length fmul_dom + List.length ([] <: list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall code_Fmul
fmul_dom
[]
_
_
(W.mk_prediction code_Fmul fmul_dom [] (fmul_lemma code_Fmul IA.win)) | {
"checked_file": "Vale.Stdcalls.X64.Fmul.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fmul.fsti"
} | [
"total"
] | [
"Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall",
"Vale.Stdcalls.X64.Fmul.code_Fmul",
"Vale.Stdcalls.X64.Fmul.fmul_dom",
"Prims.Nil",
"Vale.Interop.Base.arg",
"Vale.AsLowStar.Wrapper.pre_rel_generic",
"Vale.Interop.X64.max_stdcall",
"Vale.Interop.X64.arg_reg_stdcall",
"Vale.Stdcalls.X64.Fmul.fmul_pre",
"Vale.AsLowStar.Wrapper.post_rel_generic",
"Vale.Stdcalls.X64.Fmul.fmul_post",
"Vale.AsLowStar.Wrapper.mk_prediction",
"Vale.Interop.X64.regs_modified_stdcall",
"Vale.Interop.X64.xmms_modified_stdcall",
"Vale.Stdcalls.X64.Fmul.fmul_lemma",
"Vale.Interop.Assumptions.win",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.List.Tot.Base.length",
"Vale.Interop.Base.td",
"Prims.list"
] | [] | module Vale.Stdcalls.X64.Fmul
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fmul_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod; t64_no_mod] in
assert_norm (List.length y = 4);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fmul_pre : VSig.vale_pre fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state) ->
FW.va_req_Fmul_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2)
[@__reduce__] noextract
let fmul_post : VSig.vale_post fmul_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fmul_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fmul_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(f2:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fmul_pre code tmp f1 out f2 va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fmul_post code tmp f1 out f2 va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f2) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer f2) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fmul_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) (as_vale_buffer f2) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f2;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fmul_lemma' has the required type *)
noextract
let fmul_lemma = as_t #(VSig.vale_sig_stdcall fmul_pre fmul_post) fmul_lemma'
noextract
let code_Fmul = FW.va_code_Fmul_stdcall IA.win
(* Here's the type expected for the fmul wrapper *)
[@__reduce__] noextract | false | true | Vale.Stdcalls.X64.Fmul.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lowstar_fmul_t : Type0 | [] | Vale.Stdcalls.X64.Fmul.lowstar_fmul_t | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fmul.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 73,
"end_line": 130,
"start_col": 2,
"start_line": 123
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.