file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Spec.Salsa20.fst
Spec.Salsa20.salsa20_encrypt_block
val salsa20_encrypt_block (st0: state) (incr: counter) (b: block) : Tot block
val salsa20_encrypt_block (st0: state) (incr: counter) (b: block) : Tot block
let salsa20_encrypt_block (st0:state) (incr:counter) (b:block) : Tot block = let k = salsa20_core incr st0 in xor_block k b
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 140, "start_col": 0, "start_line": 138 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
st0: Spec.Salsa20.state -> incr: Spec.Salsa20.counter -> b: Spec.Salsa20.block -> Spec.Salsa20.block
Prims.Tot
[ "total" ]
[]
[ "Spec.Salsa20.state", "Spec.Salsa20.counter", "Spec.Salsa20.block", "Spec.Salsa20.xor_block", "Spec.Salsa20.salsa20_core" ]
[]
false
false
false
true
false
let salsa20_encrypt_block (st0: state) (incr: counter) (b: block) : Tot block =
let k = salsa20_core incr st0 in xor_block k b
false
Spec.Salsa20.fst
Spec.Salsa20.row_round
val row_round:shuffle
val row_round:shuffle
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 52, "start_col": 0, "start_line": 48 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
Spec.Salsa20.shuffle
Prims.Tot
[ "total" ]
[]
[ "Spec.Salsa20.op_At", "Spec.Salsa20.state", "Spec.Salsa20.quarter_round" ]
[]
false
false
false
true
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
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_add_counter
val salsa20_add_counter (s: state) (ctr: counter) : Tot state
val salsa20_add_counter (s: state) (ctr: counter) : Tot state
let salsa20_add_counter (s:state) (ctr:counter) : Tot state = s.[8] <- s.[8] +. (u32 ctr)
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 61, "start_col": 0, "start_line": 60 }
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 *)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
s: Spec.Salsa20.state -> ctr: Spec.Salsa20.counter -> Spec.Salsa20.state
Prims.Tot
[ "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" ]
[]
false
false
false
true
false
let salsa20_add_counter (s: state) (ctr: counter) : Tot state =
s.[ 8 ] <- s.[ 8 ] +. (u32 ctr)
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.scalar_rounds
val scalar_rounds (m: Scalar.state) : Scalar.state
val scalar_rounds (m: Scalar.state) : Scalar.state
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)))))))))
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 229, "start_col": 0, "start_line": 224 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Spec.Chacha20.state -> Spec.Chacha20.state
Prims.Tot
[ "total" ]
[]
[ "Spec.Chacha20.state", "Spec.Chacha20.double_round" ]
[]
false
false
false
true
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)))))))))
false
Spec.Salsa20.fst
Spec.Salsa20.constant0
val constant0 : u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x61707865}
let constant0 = u32 0x61707865
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 71, "start_col": 0, "start_line": 71 }
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 *)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x61707865}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.u32" ]
[]
false
false
false
false
false
let constant0 =
u32 0x61707865
false
Spec.Salsa20.fst
Spec.Salsa20.constant1
val constant1 : u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x3320646e}
let constant1 = u32 0x3320646e
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 73, "start_col": 0, "start_line": 73 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x3320646e}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.u32" ]
[]
false
false
false
false
false
let constant1 =
u32 0x3320646e
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.blocksize
val blocksize : Prims.int
let blocksize = size_block
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 19, "start_col": 0, "start_line": 19 }
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"
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Chacha20.Vec.size_block" ]
[]
false
false
false
true
false
let blocksize =
size_block
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_core
val salsa20_core (ctr: counter) (s: state) : Tot state
val salsa20_core (ctr: counter) (s: state) : Tot state
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 67, "start_col": 0, "start_line": 63 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
ctr: Spec.Salsa20.counter -> s: Spec.Salsa20.state -> Spec.Salsa20.state
Prims.Tot
[ "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" ]
[]
false
false
false
true
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
false
Spec.Salsa20.fst
Spec.Salsa20.constant2
val constant2 : u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x79622d32}
let constant2 = u32 0x79622d32
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 75, "start_col": 0, "start_line": 75 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x79622d32}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.u32" ]
[]
false
false
false
false
false
let constant2 =
u32 0x79622d32
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_key_block0
val salsa20_key_block0 (k: key) (n: nonce) : Tot block
val salsa20_key_block0 (k: key) (n: nonce) : Tot block
let salsa20_key_block0 (k:key) (n:nonce) : Tot block = let st = salsa20_init k n 0 in salsa20_key_block st
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 131, "start_col": 0, "start_line": 129 }
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'
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
k: Spec.Salsa20.key -> n: Spec.Salsa20.nonce -> Spec.Salsa20.block
Prims.Tot
[ "total" ]
[]
[ "Spec.Salsa20.key", "Spec.Salsa20.nonce", "Spec.Salsa20.salsa20_key_block", "Spec.Salsa20.state", "Spec.Salsa20.salsa20_init", "Spec.Salsa20.block" ]
[]
false
false
false
true
false
let salsa20_key_block0 (k: key) (n: nonce) : Tot block =
let st = salsa20_init k n 0 in salsa20_key_block st
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_encrypt_bytes
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}
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 171, "start_col": 0, "start_line": 169 }
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}
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
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}
Prims.Tot
[ "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" ]
[]
false
false
false
false
false
let salsa20_encrypt_bytes key nonce ctr0 msg =
let st0 = salsa20_init key nonce ctr0 in salsa20_update st0 msg
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_decrypt_bytes
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}
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 = let st0 = salsa20_init key nonce ctr0 in salsa20_update st0 cipher
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 183, "start_col": 0, "start_line": 181 }
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}
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
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}
Prims.Tot
[ "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" ]
[]
false
false
false
false
false
let salsa20_decrypt_bytes key nonce ctr0 cipher =
let st0 = salsa20_init key nonce ctr0 in salsa20_update st0 cipher
false
Spec.Salsa20.fst
Spec.Salsa20.line
val line (a b d: idx) (s: rotval U32) (m: state) : state
val line (a b d: idx) (s: rotval U32) (m: state) : state
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 34, "start_col": 0, "start_line": 32 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
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
Prims.Tot
[ "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" ]
[]
false
false
false
true
false
let line (a b d: idx) (s: rotval U32) (m: state) : state =
let m = m.[ a ] <- (m.[ a ] ^. ((m.[ b ] +. m.[ d ]) <<<. s)) in m
false
Spec.Salsa20.fst
Spec.Salsa20.xor_block
val xor_block (k: state) (b: block) : block
val xor_block (k: state) (b: block) : block
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 136, "start_col": 0, "start_line": 133 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
k: Spec.Salsa20.state -> b: Spec.Salsa20.block -> Spec.Salsa20.block
Prims.Tot
[ "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" ]
[]
false
false
false
true
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
false
Spec.Salsa20.fst
Spec.Salsa20.column_round
val column_round:shuffle
val column_round:shuffle
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 46, "start_col": 0, "start_line": 42 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
Spec.Salsa20.shuffle
Prims.Tot
[ "total" ]
[]
[ "Spec.Salsa20.op_At", "Spec.Salsa20.state", "Spec.Salsa20.quarter_round" ]
[]
false
false
false
true
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
false
Spec.Salsa20.fst
Spec.Salsa20.hsalsa20_init
val hsalsa20_init (k: key) (n: xnonce) : Tot state
val hsalsa20_init (k: key) (n: xnonce) : Tot state
let hsalsa20_init (k:key) (n:xnonce) : Tot state = let st = create 16 (u32 0) in let st = xsetup k n st in st
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 114, "start_col": 0, "start_line": 111 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
k: Spec.Salsa20.key -> n: Spec.Salsa20.xnonce -> Spec.Salsa20.state
Prims.Tot
[ "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" ]
[]
false
false
false
true
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
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_key_block
val salsa20_key_block (st: state) : Tot block
val salsa20_key_block (st: state) : Tot block
let salsa20_key_block (st:state) : Tot block = let st' = salsa20_core 0 st in uints_to_bytes_le st'
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 127, "start_col": 0, "start_line": 125 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
st: Spec.Salsa20.state -> Spec.Salsa20.block
Prims.Tot
[ "total" ]
[]
[ "Spec.Salsa20.state", "Lib.ByteSequence.uints_to_bytes_le", "Lib.IntTypes.U32", "Lib.IntTypes.SEC", "Spec.Salsa20.salsa20_core", "Spec.Salsa20.block" ]
[]
false
false
false
true
false
let salsa20_key_block (st: state) : Tot block =
let st' = salsa20_core 0 st in uints_to_bytes_le st'
false
Spec.Salsa20.fst
Spec.Salsa20.constant3
val constant3 : u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x6b206574}
let constant3 = u32 0x6b206574
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 77, "start_col": 0, "start_line": 77 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
u40: Lib.IntTypes.uint32{Lib.IntTypes.v u40 == 0x6b206574}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.u32" ]
[]
false
false
false
false
false
let constant3 =
u32 0x6b206574
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_init
val salsa20_init (k: key) (n: nonce) (ctr0: counter) : Tot state
val salsa20_init (k: key) (n: nonce) (ctr0: counter) : Tot state
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 97, "start_col": 0, "start_line": 94 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
k: Spec.Salsa20.key -> n: Spec.Salsa20.nonce -> ctr0: Spec.Salsa20.counter -> Spec.Salsa20.state
Prims.Tot
[ "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" ]
[]
false
false
false
true
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
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_update
val salsa20_update: ctx: state -> msg: bytes{length msg / size_block <= max_size_t} -> cipher: bytes{length cipher == length msg}
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)
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 159, "start_col": 0, "start_line": 155 }
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}
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
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}
Prims.Tot
[ "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" ]
[]
false
false
false
false
false
let salsa20_update ctx msg =
let cipher = msg in map_blocks size_block cipher (salsa20_encrypt_block ctx) (salsa20_encrypt_last ctx)
false
Spec.Salsa20.fst
Spec.Salsa20.salsa20_encrypt_last
val salsa20_encrypt_last (st0: state) (incr: counter) (len: size_nat{len < size_block}) (b: lbytes len) : lbytes 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 = 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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 148, "start_col": 0, "start_line": 142 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
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
Prims.Tot
[ "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" ]
[]
false
false
false
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.scalar_rounds_unroll_lemma
val scalar_rounds_unroll_lemma: m:Scalar.state -> Lemma (scalar_rounds m `Seq.equal` Scalar.rounds 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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 247, "start_col": 0, "start_line": 235 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Spec.Chacha20.state -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (Hacl.Spec.Chacha20.Equiv.scalar_rounds m) (Spec.Chacha20.rounds m))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Chacha20.state", "Lib.LoopCombinators.unfold_repeat", "Spec.Chacha20.double_round", "Prims.unit", "Lib.LoopCombinators.eq_repeat0" ]
[]
true
false
true
false
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
false
Spec.Salsa20.fst
Spec.Salsa20.xsetup
val xsetup (k: key) (n: xnonce) (st: state) : Tot state
val xsetup (k: key) (n: xnonce) (st: state) : Tot state
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 109, "start_col": 0, "start_line": 99 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
k: Spec.Salsa20.key -> n: Spec.Salsa20.xnonce -> st: Spec.Salsa20.state -> Spec.Salsa20.state
Prims.Tot
[ "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" ]
[]
false
false
false
true
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
false
Spec.Salsa20.fst
Spec.Salsa20.hsalsa20
val hsalsa20 (k: key) (n: xnonce) : Tot (lbytes 32)
val hsalsa20 (k: key) (n: xnonce) : Tot (lbytes 32)
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 123, "start_col": 0, "start_line": 116 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
k: Spec.Salsa20.key -> n: Spec.Salsa20.xnonce -> Lib.ByteSequence.lbytes 32
Prims.Tot
[ "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.Base.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" ]
[]
false
false
false
false
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
false
Spec.Salsa20.fst
Spec.Salsa20.setup
val setup (k: key) (n: nonce) (ctr0: counter) (st: state) : Tot state
val setup (k: key) (n: nonce) (ctr0: counter) (st: state) : Tot state
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
{ "file_name": "specs/Spec.Salsa20.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 92, "start_col": 0, "start_line": 80 }
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
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "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" }
false
k: Spec.Salsa20.key -> n: Spec.Salsa20.nonce -> ctr0: Spec.Salsa20.counter -> st: Spec.Salsa20.state -> Spec.Salsa20.state
Prims.Tot
[ "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" ]
[]
false
false
false
true
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.column_round_lemma_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])
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])
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 98, "end_line": 194, "start_col": 0, "start_line": 184 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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 ])
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.rounds_lemma_i
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])
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 277, "start_col": 0, "start_line": 253 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.quarter_round_lemma_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])
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])
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 178, "start_col": 0, "start_line": 167 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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 ])
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.lemma_i_div_w4
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)
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; }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 356, "start_col": 0, "start_line": 344 }
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} ->
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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; }
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.double_round_lemma_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])
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 220, "start_col": 0, "start_line": 216 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.lemma_i_div_blocksize
val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} -> Lemma (i / blocksize * blocksize + i % blocksize / 4 * 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; }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 371, "start_col": 0, "start_line": 360 }
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} ->
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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; }
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.diagonal_round_lemma_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])
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])
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 102, "end_line": 210, "start_col": 0, "start_line": 200 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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 ])
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.add_counter_lemma_aux
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))
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)
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 73, "end_line": 83, "start_col": 0, "start_line": 77 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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)
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.sum_state_lemma_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])
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])
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 123, "end_line": 284, "start_col": 0, "start_line": 283 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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 ])
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.kb_equiv_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)
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 136, "start_col": 0, "start_line": 131 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.add_counter_lemma_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))
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))
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 117, "end_line": 293, "start_col": 0, "start_line": 290 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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))
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.xor_block_scalar_lemma_i
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])
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); }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 425, "start_col": 0, "start_line": 412 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ])
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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); ( == ) { () } 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); }
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.update_sub_is_append
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)
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)
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 594, "start_col": 0, "start_line": 588 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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)
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.chacha20_core_lemma_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])
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 307, "start_col": 0, "start_line": 299 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.transpose_lemma_i
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))
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); }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 446, "start_col": 0, "start_line": 432 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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); }
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma_plain_k
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))
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 ()
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 718, "start_col": 0, "start_line": 699 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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 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); }
false
Vale.Stdcalls.X64.GCMencryptOpt.fst
Vale.Stdcalls.X64.GCMencryptOpt.gcm256_lemma'
val gcm256_lemma' (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) (code: V.va_code) (_win: bool) (auth_b: b128) (auth_bytes auth_num: uint64) (keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b: b128) (len128x6_num: uint64) (in128_b out128_b: b128) (len128_num: uint64) (inout_b: b128) (plain_num: uint64) (scratch_b tag_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\ gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\ ME.buffer_writeable (as_vale_buffer hkeys_b) /\ ME.buffer_writeable (as_vale_buffer abytes_b) /\ ME.buffer_writeable (as_vale_buffer in128x6_b) /\ ME.buffer_writeable (as_vale_buffer out128x6_b) /\ ME.buffer_writeable (as_vale_buffer in128_b) /\ ME.buffer_writeable (as_vale_buffer out128_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer scratch_b) /\ ME.buffer_writeable (as_vale_buffer tag_b)))
val gcm256_lemma' (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) (code: V.va_code) (_win: bool) (auth_b: b128) (auth_bytes auth_num: uint64) (keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b: b128) (len128x6_num: uint64) (in128_b out128_b: b128) (len128_num: uint64) (inout_b: b128) (plain_num: uint64) (scratch_b tag_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\ gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\ ME.buffer_writeable (as_vale_buffer hkeys_b) /\ ME.buffer_writeable (as_vale_buffer abytes_b) /\ ME.buffer_writeable (as_vale_buffer in128x6_b) /\ ME.buffer_writeable (as_vale_buffer out128x6_b) /\ ME.buffer_writeable (as_vale_buffer in128_b) /\ ME.buffer_writeable (as_vale_buffer out128_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer scratch_b) /\ ME.buffer_writeable (as_vale_buffer tag_b)))
let gcm256_lemma' (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) (code:V.va_code) (_win:bool) (auth_b:b128) (auth_bytes:uint64) (auth_num:uint64) (keys_b:b128) (iv_b:b128) (hkeys_b:b128) (abytes_b:b128) (in128x6_b:b128) (out128x6_b:b128) (len128x6_num:uint64) (in128_b:b128) (out128_b:b128) (len128_num:uint64) (inout_b:b128) (plain_num:uint64) (scratch_b:b128) (tag_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\ gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\ ME.buffer_writeable (as_vale_buffer hkeys_b) /\ ME.buffer_writeable (as_vale_buffer abytes_b) /\ ME.buffer_writeable (as_vale_buffer in128x6_b) /\ ME.buffer_writeable (as_vale_buffer out128x6_b) /\ ME.buffer_writeable (as_vale_buffer in128_b) /\ ME.buffer_writeable (as_vale_buffer out128_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer scratch_b) /\ ME.buffer_writeable (as_vale_buffer tag_b) )) = let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_256 (as_vale_buffer auth_b) (UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b) (as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b) (as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num) (as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b; va_s1, f
{ "file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 368, "start_col": 0, "start_line": 300 }
module Vale.Stdcalls.X64.GCMencryptOpt open FStar.HyperStack.ST module B = LowStar.Buffer module HS = FStar.HyperStack open FStar.Mul module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up 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 module GC = Vale.AES.X64.GCMencryptOpt open Vale.AES.AES_s open Vale.AES.GCM_s 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 b128 = buf_t TUInt8 TUInt128 [@__reduce__] noextract let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq [@__reduce__] noextract let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public}) [@__reduce__] noextract let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret}) [@__reduce__] noextract let tuint64 = TD_Base TUInt64 [@__reduce__] noextract let (dom: list td{List.length dom <= 20}) = let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod; t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in assert_norm (List.length y = 17); y (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) (c:V.va_code) (auth_b:b128) (auth_bytes:uint64) (auth_num:uint64) (keys_b:b128) (iv_b:b128) (hkeys_b:b128) (abytes_b:b128) (in128x6_b:b128) (out128x6_b:b128) (len128x6_num:uint64) (in128_b:b128) (out128_b:b128) (len128_num:uint64) (inout_b:b128) (plain_num:uint64) (scratch_b:b128) (tag_b:b128) (va_s0:V.va_state) -> GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128 (as_vale_buffer auth_b) (UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b) (as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b) (as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num) (as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) [@__reduce__] noextract let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) (c:V.va_code) (auth_b:b128) (auth_bytes:uint64) (auth_num:uint64) (keys_b:b128) (iv_b:b128) (hkeys_b:b128) (abytes_b:b128) (in128x6_b:b128) (out128x6_b:b128) (len128x6_num:uint64) (in128_b:b128) (out128_b:b128) (len128_num:uint64) (inout_b:b128) (plain_num:uint64) (scratch_b:b128) (tag_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128 (as_vale_buffer auth_b) (UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b) (as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b) (as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num) (as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 50" [@__reduce__] noextract let gcm128_lemma' (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) (code:V.va_code) (_win:bool) (auth_b:b128) (auth_bytes:uint64) (auth_num:uint64) (keys_b:b128) (iv_b:b128) (hkeys_b:b128) (abytes_b:b128) (in128x6_b:b128) (out128x6_b:b128) (len128x6_num:uint64) (in128_b:b128) (out128_b:b128) (len128_num:uint64) (inout_b:b128) (plain_num:uint64) (scratch_b:b128) (tag_b:b128) (va_s0:V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\ gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\ ME.buffer_writeable (as_vale_buffer hkeys_b) /\ ME.buffer_writeable (as_vale_buffer abytes_b) /\ ME.buffer_writeable (as_vale_buffer in128x6_b) /\ ME.buffer_writeable (as_vale_buffer out128x6_b) /\ ME.buffer_writeable (as_vale_buffer in128_b) /\ ME.buffer_writeable (as_vale_buffer out128_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer scratch_b) /\ ME.buffer_writeable (as_vale_buffer tag_b) )) = let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128 (as_vale_buffer auth_b) (UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b) (as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b) (as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num) (as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b; va_s1, f (* Prove that gcm128_lemma' has the required type *) noextract let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv) noextract let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128 (* Here's the type expected for the gcm wrapper *) [@__reduce__] noextract let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.as_lowstar_sig_t_weak_stdcall code_gcm128 dom [] _ _ (W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win)) (* And here's the gcm wrapper itself *) noextract let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv = assert_norm (List.length dom + List.length ([]<:list arg) <= 20); IX64.wrap_weak_stdcall code_gcm128 dom (W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win)) (* Need to rearrange the order of arguments *) [@__reduce__] noextract let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom = fun (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) (c:V.va_code) (auth_b:b128) (auth_bytes:uint64) (auth_num:uint64) (keys_b:b128) (iv_b:b128) (hkeys_b:b128) (abytes_b:b128) (in128x6_b:b128) (out128x6_b:b128) (len128x6_num:uint64) (in128_b:b128) (out128_b:b128) (len128_num:uint64) (inout_b:b128) (plain_num:uint64) (scratch_b:b128) (tag_b:b128) (va_s0:V.va_state) -> GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256 (as_vale_buffer auth_b) (UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b) (as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b) (as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num) (as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) [@__reduce__] noextract let gcm256_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom = fun (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) (c:V.va_code) (auth_b:b128) (auth_bytes:uint64) (auth_num:uint64) (keys_b:b128) (iv_b:b128) (hkeys_b:b128) (abytes_b:b128) (in128x6_b:b128) (out128x6_b:b128) (len128x6_num:uint64) (in128_b:b128) (out128_b:b128) (len128_num:uint64) (inout_b:b128) (plain_num:uint64) (scratch_b:b128) (tag_b:b128) (va_s0:V.va_state) (va_s1:V.va_state) (f:V.va_fuel) -> GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256 (as_vale_buffer auth_b) (UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b) (as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b) (as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num) (as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) va_s1 f #set-options "--z3rlimit 50"
{ "checked_file": "/", "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.AsLowStar.Wrapper.fsti.checked", "Vale.AsLowStar.ValeSig.fst.checked", "Vale.AsLowStar.MemoryHelpers.fsti.checked", "Vale.AsLowStar.LowStarSig.fst.checked", "Vale.AES.X64.GCMencryptOpt.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt64.fsti.checked", "FStar.Seq.fst.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", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.GCM_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": true, "full_module": "Vale.AES.X64.GCMencryptOpt", "short_module": "GC" }, { "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.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Vale.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 } ]
{ "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" }
false
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) -> iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE -> code: Vale.X64.Decls.va_code -> _win: Prims.bool -> auth_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> auth_bytes: Vale.Stdcalls.X64.GCMencryptOpt.uint64 -> auth_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 -> keys_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> iv_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> hkeys_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> abytes_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> in128x6_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> out128x6_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> len128x6_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 -> in128_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> out128_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> len128_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 -> inout_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> plain_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 -> scratch_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> tag_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 -> va_s0: Vale.X64.Decls.va_state -> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel)
Prims.Ghost
[]
[]
[ "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.AES.GCM_s.supported_iv_LE", "Vale.X64.Decls.va_code", "Prims.bool", "Vale.Stdcalls.X64.GCMencryptOpt.b128", "Vale.Stdcalls.X64.GCMencryptOpt.uint64", "Vale.X64.Decls.va_state", "Vale.X64.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal", "Vale.Arch.HeapTypes_s.TUInt8", "Vale.Arch.HeapTypes_s.TUInt128", "FStar.Pervasives.Native.tuple2", "Vale.X64.State.vale_state", "Vale.AES.X64.GCMencryptOpt.va_lemma_Gcm_blocks_stdcall", "Vale.Interop.Assumptions.win", "Vale.AES.AES_common_s.AES_256", "Vale.X64.MemoryAdapters.as_vale_buffer", "FStar.UInt64.v", "FStar.Ghost.reveal", "Vale.Stdcalls.X64.GCMencryptOpt.gcm256_pre", "Prims.l_and", "Vale.X64.Decls.eval_code", "Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall", "Vale.Stdcalls.X64.GCMencryptOpt.gcm256_post", "Vale.X64.Memory.buffer_writeable" ]
[]
false
false
false
false
false
let gcm256_lemma' (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) (code: V.va_code) (_win: bool) (auth_b: b128) (auth_bytes auth_num: uint64) (keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b: b128) (len128x6_num: uint64) (in128_b out128_b: b128) (len128_num: uint64) (inout_b: b128) (plain_num: uint64) (scratch_b tag_b: b128) (va_s0: V.va_state) : Ghost (V.va_state & V.va_fuel) (requires gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\ gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\ ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\ ME.buffer_writeable (as_vale_buffer hkeys_b) /\ ME.buffer_writeable (as_vale_buffer abytes_b) /\ ME.buffer_writeable (as_vale_buffer in128x6_b) /\ ME.buffer_writeable (as_vale_buffer out128x6_b) /\ ME.buffer_writeable (as_vale_buffer in128_b) /\ ME.buffer_writeable (as_vale_buffer out128_b) /\ ME.buffer_writeable (as_vale_buffer inout_b) /\ ME.buffer_writeable (as_vale_buffer scratch_b) /\ ME.buffer_writeable (as_vale_buffer tag_b))) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_256 (as_vale_buffer auth_b) (UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b) (as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b) (as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num) (as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) in Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b; Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b; va_s1, f
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.update_sub_get_last_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)
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 808, "start_col": 0, "start_line": 791 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 Lib.Sequence.div_mul_lt blocksize j w; FStar.Math.Lemmas.cancel_mul_div w blocksize; 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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.update_sub_get_block_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)
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 680, "start_col": 0, "start_line": 670 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 Lib.Sequence.div_mul_lt blocksize j w; FStar.Math.Lemmas.cancel_mul_div w blocksize; Lib.Sequence.Lemmas.get_block_s blocksize plain_v j == Lib.Sequence.Lemmas.get_block_s blocksize b_v j))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k
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)
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 922, "start_col": 0, "start_line": 918 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.update_sub_get_last_lemma_plain_v_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))
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); }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 767, "start_col": 0, "start_line": 741 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 Lib.Sequence.div_mul_lt blocksize j w; FStar.Math.Lemmas.cancel_mul_div w blocksize; let b = Lib.Sequence.Lemmas.get_block_s blocksize plain_v j in Lib.Sequence.div_interval blocksize (len / blocksize) j; FStar.Seq.Base.index b k == (match k < len % blocksize with | true -> FStar.Seq.Base.index b_v ((len / blocksize) * blocksize + k) | _ -> zero)))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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; 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); }
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.update_sub_get_block_lemma_k
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)
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 97, "end_line": 649, "start_col": 0, "start_line": 616 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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} -> 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 Lib.Sequence.div_mul_lt blocksize j w; FStar.Math.Lemmas.cancel_mul_div w blocksize; FStar.Seq.Base.index (Lib.Sequence.Lemmas.get_block_s blocksize plain_v j) k == FStar.Seq.Base.index (Lib.Sequence.Lemmas.get_block_s blocksize b_v j) k))
FStar.Pervasives.Lemma
[ "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", "FStar.Seq.Base.lemma_index_slice", "Prims.op_Addition", "Prims.unit", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Seq.Base.index", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Seq.Base.slice", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Seq.Base.lemma_index_app1", "Prims.int", "Lib.Sequence.div_mul_lt", "FStar.Math.Lemmas.multiply_fractions", "Lib.Sequence.Lemmas.get_block_s", "FStar.Math.Lemmas.cancel_mul_div", "Prims._assert", "FStar.Seq.Base.seq", "FStar.Seq.Base.append", "Hacl.Spec.Chacha20.Equiv.update_sub_is_append", "Prims.op_Subtraction", "Prims.l_and", "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" ]
[]
false
false
true
false
false
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; 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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.chacha20_core_scalar_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)
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 117, "start_col": 0, "start_line": 99 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.chacha20_init_scalar_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)
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)
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 66, "start_col": 0, "start_line": 32 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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)
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_st0_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])
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 521, "start_col": 0, "start_line": 518 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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.Math.Lemmas.cancel_mul_div w Hacl.Spec.Chacha20.Equiv.blocksize; let b = Lib.Sequence.Lemmas.get_block_s Hacl.Spec.Chacha20.Equiv.blocksize b_v j in Lib.Sequence.div_mul_lt Hacl.Spec.Chacha20.Equiv.blocksize j w; (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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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
false
Steel.ST.OnRange.fst
Steel.ST.OnRange.on_range_split
val on_range_split (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhost unit opened (on_range p i k) (fun _ -> on_range p i j `star` on_range p j k) (i <= j /\ j <= k) (fun _ -> True)
val on_range_split (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhost unit opened (on_range p i k) (fun _ -> on_range p i j `star` on_range p j k) (i <= j /\ j <= k) (fun _ -> True)
let rec on_range_split (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhost unit opened (on_range p i k) (fun _ -> on_range p i j `star` on_range p j k) (i <= j /\ j <= k) (fun _ -> True) (decreases (j - i)) = if i = j then begin rewrite emp (on_range p i j); rewrite (on_range p i k) (on_range p j k) end else begin rewrite (on_range p i k) (p i `star` on_range p (i + 1) k); on_range_split p (i + 1) j k; rewrite (p i `star` on_range p (i + 1) j) (on_range p i j) end
{ "file_name": "lib/steel/Steel.ST.OnRange.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 56, "start_col": 0, "start_line": 38 }
module Steel.ST.OnRange open Steel.ST.GenElim let rec on_range (p: (nat -> vprop)) (i j: nat) : Tot vprop (decreases (if j <= i then 0 else j - i)) = if j < i then pure False else if j = i then emp else p i `star` on_range p (i + 1) j let on_range_le p i j = if i <= j then noop () else begin rewrite (on_range p i j) (pure False); let _ = gen_elim () in rewrite emp (on_range p i j); // by contradiction noop () end let on_range_empty p i j = rewrite emp (on_range p i j) let on_range_singleton_intro p i j = rewrite (p i `star` emp) (on_range p i j) let on_range_singleton_elim p i j = rewrite (on_range p i j) (p i `star` emp)
{ "checked_file": "/", "dependencies": [ "Steel.ST.GenElim.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.OnRange.fst" }
[ { "abbrev": false, "full_module": "Steel.ST.GenElim", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: Prims.nat -> Steel.Effect.Common.vprop) -> i: Prims.nat -> j: Prims.nat -> k: Prims.nat -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[ "" ]
[]
[ "Steel.Memory.inames", "Prims.nat", "Steel.Effect.Common.vprop", "Prims.op_Equality", "Steel.ST.Util.rewrite", "Steel.ST.OnRange.on_range", "Prims.unit", "Steel.Effect.Common.emp", "Prims.bool", "Steel.Effect.Common.star", "Prims.op_Addition", "Steel.ST.OnRange.on_range_split", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_True" ]
[ "recursion" ]
false
true
false
false
false
let rec on_range_split (#opened: _) (p: (nat -> vprop)) (i j k: nat) : STGhost unit opened (on_range p i k) (fun _ -> (on_range p i j) `star` (on_range p j k)) (i <= j /\ j <= k) (fun _ -> True) (decreases (j - i)) =
if i = j then (rewrite emp (on_range p i j); rewrite (on_range p i k) (on_range p j k)) else (rewrite (on_range p i k) ((p i) `star` (on_range p (i + 1) k)); on_range_split p (i + 1) j k; rewrite ((p i) `star` (on_range p (i + 1) j)) (on_range p i j))
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.lemma_chacha20_vec_equiv
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)
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 = 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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 957, "start_col": 0, "start_line": 936 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.encrypt_block_scalar_lemma_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)
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 502, "start_col": 0, "start_line": 497 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.xor_block_vec_lemma_i
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))
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); }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 406, "start_col": 0, "start_line": 381 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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); ( == ) { () } 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); }
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.xor_block_lemma_i
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])
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); }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 477, "start_col": 0, "start_line": 454 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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); }
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.chacha20_init_lemma_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))
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
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 20, "end_line": 336, "start_col": 0, "start_line": 313 }
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))
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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)))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.lemma_label_bool
val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)]
val lemma_label_bool (r:range) (msg:string) (b:bool) : Lemma (requires label r msg b) (ensures b) [SMTPat (label r msg b)]
let lemma_label_bool r msg b = lemma_label_Type0 r msg b
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 14, "start_col": 0, "start_line": 14 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.Range.range -> msg: Prims.string -> b: Prims.bool -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.QuickCodes.label r msg b) (ensures b) [SMTPat (Vale.PPC64LE.QuickCodes.label r msg b)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Range.range", "Prims.string", "Prims.bool", "Vale.PPC64LE.QuickCodes.lemma_label_Type0", "Prims.b2t", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_label_bool r msg b =
lemma_label_Type0 r msg b
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_refl
val update_state_mods_refl (mods: mods_t) (s: state) : Lemma (ensures state_eq (update_state_mods mods s s) s)
val update_state_mods_refl (mods: mods_t) (s: state) : Lemma (ensures state_eq (update_state_mods mods s s) s)
let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 40, "start_col": 0, "start_line": 35 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> s: Vale.PPC64LE.State.state -> FStar.Pervasives.Lemma (ensures Vale.PPC64LE.State.state_eq (Vale.PPC64LE.QuickCode.update_state_mods mods s s) s)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCode.mod_t", "Prims.list", "Vale.PPC64LE.QuickCodes.update_state_mods_refl", "Prims.unit", "Prims.l_True", "Prims.squash", "Vale.PPC64LE.State.state_eq", "Vale.PPC64LE.QuickCode.update_state_mods", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec update_state_mods_refl (mods: mods_t) (s: state) : Lemma (ensures state_eq (update_state_mods mods s s) s) =
match mods with | [] -> () | _ :: mods -> update_state_mods_refl mods s
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.empty_list_is_small
val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x)
val empty_list_is_small (#a:Type) (x:list a) : Lemma ([] #a == x \/ [] #a << x)
let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 19, "start_col": 0, "start_line": 16 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.list a -> FStar.Pervasives.Lemma (ensures [] == x \/ [] << x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Vale.PPC64LE.QuickCodes.empty_list_is_small", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec empty_list_is_small #a x =
match x with | [] -> () | h :: t -> empty_list_is_small t
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_weaken1
val update_state_mods_weaken1 (mods mods': mods_t) (s' s: state) (m0: mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s'))
val update_state_mods_weaken1 (mods mods': mods_t) (s' s: state) (m0: mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s'))
let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 135, "start_col": 0, "start_line": 127 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> mods': Vale.PPC64LE.QuickCode.mods_t -> s': Vale.PPC64LE.State.state -> s: Vale.PPC64LE.State.state -> m0: Vale.PPC64LE.QuickCode.mod_t -> FStar.Pervasives.Lemma (requires (Vale.PPC64LE.QuickCodes.mods_contains1 mods m0 \/ Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s') /\ Vale.PPC64LE.QuickCodes.mods_contains mods' mods) (ensures Vale.PPC64LE.QuickCodes.mods_contains1 mods' m0 \/ Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCode.mod_t", "Prims.list", "Prims.op_AmpAmp", "Vale.PPC64LE.QuickCodes.mods_contains", "Vale.PPC64LE.QuickCodes.mods_contains1", "Vale.PPC64LE.QuickCodes.update_state_mods_weaken1", "Prims.bool", "Prims.unit", "Prims.l_and", "Prims.l_or", "Prims.b2t", "Vale.PPC64LE.QuickCodes.state_mod_eq", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec update_state_mods_weaken1 (mods mods': mods_t) (s' s: state) (m0: mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) =
match mods with | [] -> () | _ :: mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_vec_equiv_pre_k0
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)
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); }
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 851, "start_col": 0, "start_line": 830 }
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)
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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))
FStar.Pervasives.Lemma
[ "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" ]
[]
false
false
true
false
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); }
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_weaken
val update_state_mods_weaken (mods mods': mods_t) (s' s: state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s')
val update_state_mods_weaken (mods mods': mods_t) (s' s: state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s')
let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 146, "start_col": 0, "start_line": 137 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> mods': Vale.PPC64LE.QuickCode.mods_t -> s': Vale.PPC64LE.State.state -> s: Vale.PPC64LE.State.state -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.QuickCode.update_state_mods mods s' s == s' /\ Vale.PPC64LE.QuickCodes.mods_contains mods' mods) (ensures Vale.PPC64LE.QuickCode.update_state_mods mods' s' s == s')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCodes.update_state_mods_to", "Prims.unit", "FStar.Classical.forall_intro", "Vale.PPC64LE.QuickCode.mod_t", "Prims.l_or", "Prims.b2t", "Vale.PPC64LE.QuickCodes.mods_contains1", "Vale.PPC64LE.QuickCodes.state_mod_eq", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.PPC64LE.QuickCodes.update_state_mods_weaken1", "Vale.PPC64LE.QuickCodes.update_state_mods_from", "Prims.l_and", "Prims.eq2", "Vale.PPC64LE.QuickCode.update_state_mods", "Vale.PPC64LE.QuickCodes.mods_contains" ]
[]
false
false
true
false
false
let update_state_mods_weaken (mods mods': mods_t) (s' s: state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') =
update_state_mods_from mods s' s; let f1 (m0: mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_not1
val update_state_mods_not1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s))
val update_state_mods_not1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s))
let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 48, "start_col": 0, "start_line": 42 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> s': Vale.PPC64LE.State.state -> s: Vale.PPC64LE.State.state -> m0: Vale.PPC64LE.QuickCode.mod_t -> FStar.Pervasives.Lemma (requires Prims.op_Negation (Vale.PPC64LE.QuickCodes.mods_contains1 mods m0)) (ensures Vale.PPC64LE.QuickCodes.state_mod_eq m0 s (Vale.PPC64LE.QuickCode.update_state_mods mods s' s))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCode.mod_t", "Prims.list", "Vale.PPC64LE.QuickCodes.update_state_mods_not1", "Prims.unit", "Prims.b2t", "Prims.op_Negation", "Vale.PPC64LE.QuickCodes.mods_contains1", "Prims.squash", "Vale.PPC64LE.QuickCodes.state_mod_eq", "Vale.PPC64LE.QuickCode.update_state_mods", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec update_state_mods_not1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) =
match mods with | [] -> () | _ :: mods -> update_state_mods_not1 mods s' s m0
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.state_mod_eq
val state_mod_eq : m: Vale.PPC64LE.QuickCode.mod_t -> s1: Vale.PPC64LE.State.state -> s2: Vale.PPC64LE.State.state -> Prims.logical
let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 33, "start_col": 0, "start_line": 21 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Vale.PPC64LE.QuickCode.mod_t -> s1: Vale.PPC64LE.State.state -> s2: Vale.PPC64LE.State.state -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Vale.PPC64LE.QuickCode.mod_t", "Vale.PPC64LE.State.state", "Prims.l_True", "Prims.eq2", "Prims.bool", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ok", "Vale.PPC64LE.Machine_s.reg", "Vale.PPC64LE.Machine_s.nat64", "Vale.PPC64LE.State.eval_reg", "Vale.PPC64LE.Machine_s.vec", "Vale.PPC64LE.Machine_s.quad32", "Vale.PPC64LE.State.eval_vec", "Vale.PPC64LE.Machine_s.cr0_t", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__cr0", "Vale.PPC64LE.Machine_s.xer_t", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__xer", "Vale.Arch.HeapImpl.vale_heap", "Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heap", "Vale.PPC64LE.Decls.coerce", "Vale.Arch.HeapImpl.vale_full_heap", "Vale.Arch.Heap.heap_impl", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.Arch.HeapImpl.vale_heap_layout", "Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_layout", "Vale.PPC64LE.Decls.heaplet_id", "Vale.Lib.Map16.sel", "Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets", "Vale.PPC64LE.Machine_s.machine_stack", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.Arch.HeapTypes_s.memTaint_t", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Prims.logical" ]
[]
false
false
false
true
true
let state_mod_eq (m: mod_t) (s1 s2: state) =
match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_from
val update_state_mods_from (mods: mods_t) (s' s: state) : Lemma (requires update_state_mods mods s' s == s') (ensures (forall (m0: mod_t). {:pattern mods_contains1 mods m0\/state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s'))
val update_state_mods_from (mods: mods_t) (s' s: state) : Lemma (requires update_state_mods mods s' s == s') (ensures (forall (m0: mod_t). {:pattern mods_contains1 mods m0\/state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s'))
let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 79, "start_col": 0, "start_line": 69 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> s': Vale.PPC64LE.State.state -> s: Vale.PPC64LE.State.state -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.QuickCode.update_state_mods mods s' s == s') (ensures forall (m0: Vale.PPC64LE.QuickCode.mod_t). {:pattern Vale.PPC64LE.QuickCodes.mods_contains1 mods m0\/Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s'} Vale.PPC64LE.QuickCodes.mods_contains1 mods m0 \/ Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "FStar.Classical.forall_intro", "Vale.PPC64LE.QuickCode.mod_t", "Prims.l_or", "Prims.b2t", "Vale.PPC64LE.QuickCodes.mods_contains1", "Vale.PPC64LE.QuickCodes.state_mod_eq", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.PPC64LE.QuickCodes.update_state_mods_from1", "Prims.eq2", "Vale.PPC64LE.QuickCode.update_state_mods", "Prims.l_Forall" ]
[]
false
false
true
false
false
let update_state_mods_from (mods: mods_t) (s' s: state) : Lemma (requires update_state_mods mods s' s == s') (ensures (forall (m0: mod_t). {:pattern mods_contains1 mods m0\/state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s')) =
let f1 (m0: mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.call_QPURE
val call_QPURE (#a: Type0) (#cs: codes) (r: range) (msg: string) (pre: ((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l: (unit -> PURE unit (as_pure_wp pre))) (qcs: quickCodes a cs) (mods: mods_t) (k: (state -> a -> Type0)) (s0: state) : Lemma (requires (forall (p: (unit -> GTot Type0)). {:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0)
val call_QPURE (#a: Type0) (#cs: codes) (r: range) (msg: string) (pre: ((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l: (unit -> PURE unit (as_pure_wp pre))) (qcs: quickCodes a cs) (mods: mods_t) (k: (state -> a -> Type0)) (s0: state) : Lemma (requires (forall (p: (unit -> GTot Type0)). {:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0)
let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l ()
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 157, "start_col": 0, "start_line": 148 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.Range.range -> msg: Prims.string -> pre: (_: (_: Prims.unit -> Prims.GTot Type0) -> Prims.GTot Type0) {FStar.Monotonic.Pure.is_monotonic pre} -> l: (_: Prims.unit -> Prims.PURE Prims.unit) -> qcs: Vale.PPC64LE.QuickCodes.quickCodes a cs -> mods: Vale.PPC64LE.QuickCode.mods_t -> k: (_: Vale.PPC64LE.State.state -> _: a -> Type0) -> s0: Vale.PPC64LE.State.state -> FStar.Pervasives.Lemma (requires forall (p: (_: Prims.unit -> Prims.GTot Type0)). {:pattern pre p} (Vale.PPC64LE.QuickCodes.wp cs qcs mods k s0 ==> p ()) ==> Vale.PPC64LE.QuickCodes.label r msg (pre p)) (ensures Vale.PPC64LE.QuickCodes.wp cs qcs mods k s0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCodes.codes", "FStar.Range.range", "Prims.string", "Prims.unit", "FStar.Monotonic.Pure.is_monotonic", "FStar.Monotonic.Pure.as_pure_wp", "Vale.PPC64LE.QuickCodes.quickCodes", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Prims.l_Forall", "Prims.l_imp", "Vale.PPC64LE.QuickCodes.wp", "Vale.PPC64LE.QuickCodes.label", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let call_QPURE (#a: Type0) (#cs: codes) (r: range) (msg: string) (pre: ((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l: (unit -> PURE unit (as_pure_wp pre))) (qcs: quickCodes a cs) (mods: mods_t) (k: (state -> a -> Type0)) (s0: state) : Lemma (requires (forall (p: (unit -> GTot Type0)). {:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) =
l ()
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_from1
val update_state_mods_from1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s')
val update_state_mods_from1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s')
let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 54, "start_col": 0, "start_line": 50 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> s': Vale.PPC64LE.State.state -> s: Vale.PPC64LE.State.state -> m0: Vale.PPC64LE.QuickCode.mod_t -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.QuickCodes.state_mod_eq m0 s' (Vale.PPC64LE.QuickCode.update_state_mods mods s' s)) (ensures Vale.PPC64LE.QuickCodes.mods_contains1 mods m0 \/ Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCode.mod_t", "Prims.op_Negation", "Vale.PPC64LE.QuickCodes.mods_contains1", "Vale.PPC64LE.QuickCodes.update_state_mods_not1", "Prims.bool", "Prims.unit", "Vale.PPC64LE.QuickCodes.state_mod_eq", "Vale.PPC64LE.QuickCode.update_state_mods", "Prims.squash", "Prims.l_or", "Prims.b2t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let update_state_mods_from1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') =
if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.qAssertLemma
val qAssertLemma (p:Type0) : tAssertLemma p
val qAssertLemma (p:Type0) : tAssertLemma p
let qAssertLemma p = fun () -> ()
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 320, "start_col": 0, "start_line": 320 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) ) let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) let rec qWhile_proof_rec (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:state -> a -> Type0) (dec:state -> a -> d) (s0 s1:state) (g1:a) (f1:fuel) (k:state -> a -> Type0) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2 ) (decreases (dec s1 g1)) = let ob = cmp_to_ocmp b in let s1' = {s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b)} in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then ( let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let (s2, f2) = va_lemma_whileTrue_total ob c s0 s1 f1 in let (sc, fc, gc) = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k ) else ( let (s2, f2) = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1) ) let qWhile_proof #a #d #c b qc mods inv dec g0 s0 k = let ob = cmp_to_ocmp b in let (s1, f1) = va_lemma_while_total ob c s0 in update_state_mods_refl mods s0; qWhile_proof_rec b qc mods inv dec s0 s1 g0 f1 k
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Type0 -> Vale.PPC64LE.QuickCodes.tAssertLemma p
Prims.Tot
[ "total" ]
[]
[ "Prims.unit" ]
[]
false
false
false
true
false
let qAssertLemma p =
fun () -> ()
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.qWhile_proof
val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
val qWhile_proof (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:va_state -> a -> Type0) (dec:va_state -> a -> d) (g0:a) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_While b qc mods inv dec g0 s0 k) (ensures fun (sM, f0, g) -> eval_code (While (cmp_to_ocmp b) c) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
let qWhile_proof #a #d #c b qc mods inv dec g0 s0 k = let ob = cmp_to_ocmp b in let (s1, f1) = va_lemma_while_total ob c s0 in update_state_mods_refl mods s0; qWhile_proof_rec b qc mods inv dec s0 s1 g0 f1 k
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 318, "start_col": 0, "start_line": 314 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) ) let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) let rec qWhile_proof_rec (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:state -> a -> Type0) (dec:state -> a -> d) (s0 s1:state) (g1:a) (f1:fuel) (k:state -> a -> Type0) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2 ) (decreases (dec s1 g1)) = let ob = cmp_to_ocmp b in let s1' = {s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b)} in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then ( let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let (s2, f2) = va_lemma_whileTrue_total ob c s0 s1 f1 in let (sc, fc, gc) = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k ) else ( let (s2, f2) = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1) )
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.PPC64LE.QuickCodes.cmp -> qc: (_: a -> Vale.PPC64LE.QuickCode.quickCode a c) -> mods: Vale.PPC64LE.QuickCode.mods_t -> inv: (_: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> dec: (_: Vale.PPC64LE.Decls.va_state -> _: a -> d) -> g0: a -> s0: Vale.PPC64LE.Decls.va_state -> k: (_: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> Prims.Ghost ((Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.Decls.va_fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.code", "Vale.PPC64LE.QuickCodes.cmp", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.Decls.va_state", "Vale.PPC64LE.Decls.va_fuel", "Vale.PPC64LE.QuickCodes.qWhile_proof_rec", "Prims.unit", "Vale.PPC64LE.QuickCodes.update_state_mods_refl", "FStar.Pervasives.Native.tuple3", "FStar.Pervasives.Native.tuple2", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_lemma_while_total", "Vale.PPC64LE.Decls.ocmp", "Vale.PPC64LE.QuickCodes.cmp_to_ocmp" ]
[]
false
false
false
false
false
let qWhile_proof #a #d #c b qc mods inv dec g0 s0 k =
let ob = cmp_to_ocmp b in let s1, f1 = va_lemma_while_total ob c s0 in update_state_mods_refl mods s0; qWhile_proof_rec b qc mods inv dec s0 s1 g0 f1 k
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.qblock_proof
val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
val qblock_proof (#a:Type) (#cs:codes) (qcs:va_state -> GTot (quickCodes a cs)) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_block qcs mods s0 k) (ensures fun (sM, f0, g) -> eval_code (block cs) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 234, "start_col": 0, "start_line": 233 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
qcs: (_: Vale.PPC64LE.Decls.va_state -> Prims.GTot (Vale.PPC64LE.QuickCodes.quickCodes a cs)) -> mods: Vale.PPC64LE.QuickCode.mods_t -> s0: Vale.PPC64LE.Decls.va_state -> k: (_: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> Prims.Ghost ((Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.Decls.va_fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.codes", "Vale.PPC64LE.Decls.va_state", "Vale.PPC64LE.QuickCodes.quickCodes", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.QuickCodes.wp_sound", "FStar.Pervasives.Native.tuple3", "Vale.PPC64LE.Decls.va_fuel" ]
[]
false
false
false
false
false
let qblock_proof #a #cs qcs mods s0 k =
wp_sound cs (qcs s0) mods k s0
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.wp_sound
val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN )
val wp_sound (#a:Type0) (cs:codes) (qcs:quickCodes a cs) (mods:mods_t) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp cs qcs mods k s0) (ensures fun (sN, fN, gN) -> eval (Block cs) s0 fN sN /\ update_state_mods mods sN s0 == sN /\ state_inv sN /\ k sN gN )
let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 231, "start_col": 0, "start_line": 174 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *)
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cs: Vale.PPC64LE.QuickCodes.codes -> qcs: Vale.PPC64LE.QuickCodes.quickCodes a cs -> mods: Vale.PPC64LE.QuickCode.mods_t -> k: (_: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> s0: Vale.PPC64LE.Decls.va_state -> Prims.Ghost ((Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.Decls.va_fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.codes", "Vale.PPC64LE.QuickCodes.quickCodes", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.Decls.va_state", "Vale.PPC64LE.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple3", "FStar.Pervasives.Native.tuple3", "FStar.Pervasives.Native.tuple2", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.Decls.va_lemma_empty_total", "Prims.Nil", "Vale.PPC64LE.Decls.va_code", "Prims.unit", "Vale.PPC64LE.QuickCodes.update_state_mods_refl", "Vale.PPC64LE.QuickCodes.code", "FStar.Range.range", "Prims.string", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.QuickCode.quickProc_wp", "Vale.PPC64LE.QuickCode.t_proof", "Prims.list", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCodes.update_state_mods_trans", "Vale.PPC64LE.QuickCodes.update_state_mods_weaken", "Vale.PPC64LE.QuickCode.__proj__QProc__item__mods", "Vale.PPC64LE.Decls.va_lemma_merge_total", "Prims.Cons", "Vale.PPC64LE.QuickCodes.wp_sound", "Vale.PPC64LE.QuickCodes.wp_Seq_t", "Vale.PPC64LE.QuickCodes.wp_Seq", "Vale.PPC64LE.Machine_s.precode", "Vale.PPC64LE.Decls.ins", "Vale.PPC64LE.Decls.ocmp", "Vale.PPC64LE.QuickCodes.wp_Bind_t", "Vale.PPC64LE.QuickCodes.wp_Bind", "FStar.Monotonic.Pure.is_monotonic", "FStar.Monotonic.Pure.as_pure_wp", "Vale.PPC64LE.QuickCodes.call_QPURE", "Prims.squash", "FStar.Pervasives.pattern", "Vale.PPC64LE.QuickCodes.k_AssertBy", "Vale.PPC64LE.QuickCodes.empty_list_is_small" ]
[ "recursion" ]
false
false
false
false
false
let rec wp_sound #a cs qcs mods k s0 =
let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let sN, fN = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c :: cs = cs in let k' = wp_Seq cs qcs mods k in let sM, fM, gM = proof s0 k' in let sN, fN, gN = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c :: cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c :: cs = cs in let k' = wp_Bind cs qcs mods k in let sM, fM, gM = proof s0 k' in let sN, fN, gN = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c :: cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c :: cs = cs in let sM, fM = va_lemma_empty_total s0 [] in let sN, fN, gN = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c :: cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c :: cs = cs in let sM, fM = va_lemma_empty_total s0 [] in let g = l () in let sN, fN, gN = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c :: cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_trans
val update_state_mods_trans (mods: mods_t) (s0 s1 s2: state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2)
val update_state_mods_trans (mods: mods_t) (s0 s1 s2: state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2)
let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 125, "start_col": 0, "start_line": 119 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> s0: Vale.PPC64LE.State.state -> s1: Vale.PPC64LE.State.state -> s2: Vale.PPC64LE.State.state -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.QuickCode.update_state_mods mods s1 s0 == s1 /\ Vale.PPC64LE.QuickCode.update_state_mods mods s2 s1 == s2) (ensures Vale.PPC64LE.QuickCode.update_state_mods mods s2 s0 == s2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCodes.update_state_mods_to", "Prims.unit", "Vale.PPC64LE.QuickCodes.update_state_mods_from", "Prims.l_and", "Prims.eq2", "Vale.PPC64LE.QuickCode.update_state_mods", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let update_state_mods_trans (mods: mods_t) (s0 s1 s2: state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) =
update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.qas_nat4_is_qas_nat
val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3]))
let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 26, "start_col": 0, "start_line": 21 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) :
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Spec.K256.Scalar.qelem_lseq -> FStar.Pervasives.Lemma (ensures Hacl.Spec.Bignum.Definitions.bn_v f == Hacl.Spec.K256.Scalar.qas_nat4 (f.[ 0 ], f.[ 1 ], f.[ 2 ], f.[ 3 ]))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem_lseq", "Hacl.Spec.Bignum.Definitions.bn_eval0", "Lib.IntTypes.U64", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i" ]
[]
true
false
true
false
false
let qas_nat4_is_qas_nat f =
SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_to
val update_state_mods_to (mods: mods_t) (s' s: state) : Lemma (requires (forall (m0: mod_t). {:pattern mods_contains1 mods m0\/state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s')) (ensures state_eq s' (update_state_mods mods s' s))
val update_state_mods_to (mods: mods_t) (s' s: state) : Lemma (requires (forall (m0: mod_t). {:pattern mods_contains1 mods m0\/state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s')) (ensures state_eq s' (update_state_mods mods s' s))
let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in ()
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 117, "start_col": 0, "start_line": 81 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> s': Vale.PPC64LE.State.state -> s: Vale.PPC64LE.State.state -> FStar.Pervasives.Lemma (requires forall (m0: Vale.PPC64LE.QuickCode.mod_t). {:pattern Vale.PPC64LE.QuickCodes.mods_contains1 mods m0\/Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s'} Vale.PPC64LE.QuickCodes.mods_contains1 mods m0 \/ Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s') (ensures Vale.PPC64LE.State.state_eq s' (Vale.PPC64LE.QuickCode.update_state_mods mods s' s))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.Arch.HeapImpl.heaplet_id", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Arch.HeapImpl.vale_heap", "Vale.Lib.Map16.sel", "Vale.Arch.HeapImpl.__proj__Mkvale_full_heap__item__vf_heaplets", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil", "Vale.PPC64LE.QuickCode.Mod_mem_heaplet", "Vale.PPC64LE.Decls.coerce", "Vale.Arch.HeapImpl.vale_full_heap", "Vale.Arch.Heap.heap_impl", "Vale.PPC64LE.Machine_s.vec", "Vale.Def.Types_s.quad32", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.PPC64LE.QuickCode.Mod_vec", "Vale.PPC64LE.Machine_s.quad32", "Vale.PPC64LE.Machine_s.reg", "Vale.Def.Words_s.nat64", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.PPC64LE.QuickCode.Mod_reg", "Vale.PPC64LE.Machine_s.nat64", "Vale.PPC64LE.QuickCode.Mod_stackTaint", "Vale.PPC64LE.QuickCode.Mod_stack", "Vale.PPC64LE.QuickCode.Mod_mem_layout", "Vale.PPC64LE.QuickCode.Mod_mem", "Vale.PPC64LE.QuickCode.Mod_xer", "Vale.PPC64LE.QuickCode.Mod_cr0", "Vale.PPC64LE.QuickCode.Mod_ok", "Vale.PPC64LE.QuickCode.mod_t", "Vale.PPC64LE.QuickCodes.state_mod_eq", "Vale.PPC64LE.QuickCodes.update_state_mods_to1", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.QuickCode.update_state_mods", "Prims.l_Forall", "Prims.l_or", "Prims.b2t", "Vale.PPC64LE.QuickCodes.mods_contains1", "Vale.PPC64LE.State.state_eq" ]
[]
false
false
true
false
false
let update_state_mods_to (mods: mods_t) (s' s: state) : Lemma (requires (forall (m0: mod_t). {:pattern mods_contains1 mods m0\/state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s')) (ensures state_eq s' (update_state_mods mods s' s)) =
let s'' = update_state_mods mods s' s in let f1 (m0: mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r: reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v: vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n: heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in ()
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.is_qelem_le_q_halved_vartime4_lemma
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2))
let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 61, "start_col": 0, "start_line": 59 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 ->
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Spec.K256.Scalar.qelem4 -> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Scalar.is_qelem_le_q_halved_vartime4 f == (Hacl.Spec.K256.Scalar.qas_nat4 f <= Spec.K256.PointOps.q / 2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem4", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Division", "Spec.K256.PointOps.q", "Prims.unit" ]
[]
true
false
true
false
false
let is_qelem_le_q_halved_vartime4_lemma f =
assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2)
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.qAssertSquashLemma
val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p
val qAssertSquashLemma (p:Type0) : tAssertSquashLemma p
let qAssertSquashLemma p = fun () -> ()
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 322, "start_col": 0, "start_line": 322 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) ) let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) let rec qWhile_proof_rec (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:state -> a -> Type0) (dec:state -> a -> d) (s0 s1:state) (g1:a) (f1:fuel) (k:state -> a -> Type0) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2 ) (decreases (dec s1 g1)) = let ob = cmp_to_ocmp b in let s1' = {s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b)} in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then ( let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let (s2, f2) = va_lemma_whileTrue_total ob c s0 s1 f1 in let (sc, fc, gc) = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k ) else ( let (s2, f2) = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1) ) let qWhile_proof #a #d #c b qc mods inv dec g0 s0 k = let ob = cmp_to_ocmp b in let (s1, f1) = va_lemma_while_total ob c s0 in update_state_mods_refl mods s0; qWhile_proof_rec b qc mods inv dec s0 s1 g0 f1 k let qAssertLemma p = fun () -> ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Type0 -> Vale.PPC64LE.QuickCodes.tAssertSquashLemma p
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Prims.squash" ]
[]
false
false
false
true
false
let qAssertSquashLemma p =
fun () -> ()
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.qIf_proof
val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
val qIf_proof (#a:Type) (#c1:code) (#c2:code) (b:cmp) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_If b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (IfElse (cmp_to_ocmp b) c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) )
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 276, "start_col": 0, "start_line": 250 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) )
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.PPC64LE.QuickCodes.cmp -> qc1: Vale.PPC64LE.QuickCode.quickCode a c1 -> qc2: Vale.PPC64LE.QuickCode.quickCode a c2 -> mods: Vale.PPC64LE.QuickCode.mods_t -> s0: Vale.PPC64LE.Decls.va_state -> k: (_: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> Prims.Ghost ((Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.Decls.va_fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.code", "Vale.PPC64LE.QuickCodes.cmp", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.Decls.va_state", "Vale.PPC64LE.QuickCodes.eval_cmp", "Vale.PPC64LE.State.state", "Vale.PPC64LE.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple3", "Prims.unit", "Vale.PPC64LE.QuickCodes.update_state_mods_trans", "Vale.PPC64LE.QuickCodes.update_state_mods_weaken", "Vale.PPC64LE.QuickCode.__proj__QProc__item__mods", "Vale.PPC64LE.Decls.va_lemma_ifElseTrue_total", "Vale.PPC64LE.QuickCodes.cmp_to_ocmp", "FStar.Pervasives.Native.tuple3", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.QuickCode.__proj__QProc__item__proof", "Prims.bool", "Vale.PPC64LE.Decls.va_lemma_ifElseFalse_total", "Vale.PPC64LE.QuickCodes.update_state_mods_to", "Vale.PPC64LE.Machine_s.Mkstate", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ok", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.PPC64LE.Decls.eval_cmp_cr0", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__xer", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Vale.PPC64LE.Machine_s.cmp_opr", "Vale.PPC64LE.Decls.lemma_cmp_eq", "Vale.PPC64LE.Decls.lemma_valid_cmp_eq", "Vale.PPC64LE.Decls.lemma_cmp_ne", "Vale.PPC64LE.Decls.lemma_valid_cmp_ne", "Vale.PPC64LE.Decls.lemma_cmp_le", "Vale.PPC64LE.Decls.lemma_valid_cmp_le", "Vale.PPC64LE.Decls.lemma_cmp_ge", "Vale.PPC64LE.Decls.lemma_valid_cmp_ge", "Vale.PPC64LE.Decls.lemma_cmp_lt", "Vale.PPC64LE.Decls.lemma_valid_cmp_lt", "Vale.PPC64LE.Decls.lemma_cmp_gt", "Vale.PPC64LE.Decls.lemma_valid_cmp_gt" ]
[]
false
false
false
false
false
let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k =
(match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2); let s1 = { s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b) } in update_state_mods_to mods s1 s0; if eval_cmp s0 b then (let sM, f0, g = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g)) else (let sM, f0, g = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g))
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.qas_nat4_inj
val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 43, "start_col": 0, "start_line": 36 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.K256.Scalar.qelem4 -> f2: Hacl.Spec.K256.Scalar.qelem4 -> FStar.Pervasives.Lemma (requires Hacl.Spec.K256.Scalar.qas_nat4 f1 = Hacl.Spec.K256.Scalar.qas_nat4 f2) (ensures (let _ = f1 in (let FStar.Pervasives.Native.Mktuple4 #_ #_ #_ #_ a0 a1 a2 a3 = _ in let _ = f2 in (let FStar.Pervasives.Native.Mktuple4 #_ #_ #_ #_ b0 b1 b2 b3 = _ in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem4", "Lib.IntTypes.uint64", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Lib.IntTypes.U64", "Prims.unit", "Hacl.Spec.K256.Scalar.Lemmas.qas_nat4_is_qas_nat", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.Sequence.create4" ]
[]
false
false
true
false
false
let qas_nat4_inj f1 f2 =
let a0, a1, a2, a3 = f1 in let b0, b1, b2, b3 = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.wp_sound_code_wrap
val wp_sound_code_wrap (#a: Type0) (c: code) (qc: quickCode a c) (s0: state) (k: (s0': state{s0 == s0'} -> state -> a -> Type0)) : Ghost (state & fuel & a) (t_require s0 /\ wp_sound_code_pre qc s0 k) (wp_sound_code_post qc s0 k)
val wp_sound_code_wrap (#a: Type0) (c: code) (qc: quickCode a c) (s0: state) (k: (s0': state{s0 == s0'} -> state -> a -> Type0)) : Ghost (state & fuel & a) (t_require s0 /\ wp_sound_code_pre qc s0 k) (wp_sound_code_post qc s0 k)
let wp_sound_code_wrap (#a:Type0) (c:code) (qc:quickCode a c) (s0:state) (k:(s0':state{s0 == s0'}) -> state -> a -> Type0) : Ghost (state & fuel & a) (t_require s0 /\ wp_sound_code_pre qc s0 k) (wp_sound_code_post qc s0 k) = wp_sound_code c qc (k s0) s0
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 339, "start_col": 0, "start_line": 334 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) ) let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) let rec qWhile_proof_rec (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:state -> a -> Type0) (dec:state -> a -> d) (s0 s1:state) (g1:a) (f1:fuel) (k:state -> a -> Type0) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2 ) (decreases (dec s1 g1)) = let ob = cmp_to_ocmp b in let s1' = {s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b)} in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then ( let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let (s2, f2) = va_lemma_whileTrue_total ob c s0 s1 f1 in let (sc, fc, gc) = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k ) else ( let (s2, f2) = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1) ) let qWhile_proof #a #d #c b qc mods inv dec g0 s0 k = let ob = cmp_to_ocmp b in let (s1, f1) = va_lemma_while_total ob c s0 in update_state_mods_refl mods s0; qWhile_proof_rec b qc mods inv dec s0 s1 g0 f1 k let qAssertLemma p = fun () -> () let qAssumeLemma p = fun () -> assume p let qAssertSquashLemma p = fun () -> () //let qAssertByLemma #a p qcs mods s0 = // fun () -> let _ = wp_sound [] qcs mods (fun _ _ -> p) s0 in () let wp_sound_code #a c qc k s0 = let QProc c _ wp proof = qc in proof s0 k let lemma_state_match s0 s1 = ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.PPC64LE.QuickCodes.code -> qc: Vale.PPC64LE.QuickCode.quickCode a c -> s0: Vale.PPC64LE.State.state -> k: (s0': Vale.PPC64LE.State.state{s0 == s0'} -> _: Vale.PPC64LE.State.state -> _: a -> Type0) -> Prims.Ghost ((Vale.PPC64LE.State.state * Vale.PPC64LE.QuickCodes.fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.code", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.State.state", "Prims.eq2", "Vale.PPC64LE.QuickCodes.wp_sound_code", "FStar.Pervasives.Native.tuple3", "Vale.PPC64LE.QuickCodes.fuel", "Prims.l_and", "Vale.PPC64LE.QuickCode.t_require", "Vale.PPC64LE.QuickCodes.wp_sound_code_pre", "Vale.PPC64LE.QuickCodes.wp_sound_code_post" ]
[]
false
false
false
false
false
let wp_sound_code_wrap (#a: Type0) (c: code) (qc: quickCode a c) (s0: state) (k: (s0': state{s0 == s0'} -> state -> a -> Type0)) : Ghost (state & fuel & a) (t_require s0 /\ wp_sound_code_pre qc s0 k) (wp_sound_code_post qc s0 k) =
wp_sound_code c qc (k s0) s0
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.lemma_get_carry_from_bn_add
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat -> Lemma ((r + c * pow2 256) / pow2 256 = c)
val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat -> Lemma ((r + c * pow2 256) / pow2 256 = c)
let lemma_get_carry_from_bn_add r c = Math.Lemmas.lemma_div_plus r c (pow2 256); Math.Lemmas.small_div r (pow2 256)
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 113, "start_col": 0, "start_line": 111 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2)) let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2) val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2)) let is_qelem_eq_vartime4_lemma f1 f2 = if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2 #pop-options val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128)) let is_qelem_lt_pow2_128_vartime4_lemma f = let (f0, f1, f2, f3) = f in assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192); assert (v f0 + v f1 * pow2 64 < pow2 128); if v f2 = 0 && v f3 = 0 then () else begin Math.Lemmas.pow2_lt_compat 192 128; assert (pow2 128 <= qas_nat4 f) end val lemma_check_overflow: b:nat{b < pow2 256} -> Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in overflow = (if b < S.q then 0 else 1)) let lemma_check_overflow b = let overflow = (b + (pow2 256 - S.q)) / pow2 256 in if b < S.q then begin assert (pow2 256 + b - S.q < pow2 256); assert (pow2 256 - S.q <= pow2 256 + b - S.q); assert_norm (0 < pow2 256 - S.q); Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256); assert (overflow = 0) end else begin assert (pow2 256 <= pow2 256 + b - S.q); Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256); Math.Lemmas.cancel_mul_div 1 (pow2 256); assert (1 <= overflow); assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q); assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1); Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256); assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1); assert (overflow <= 1) end val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat -> Lemma ((r + c * pow2 256) / pow2 256 = c)
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Prims.nat{r < Prims.pow2 256} -> c: Prims.nat -> FStar.Pervasives.Lemma (ensures (r + c * Prims.pow2 256) / Prims.pow2 256 = c)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Math.Lemmas.small_div", "Prims.unit", "FStar.Math.Lemmas.lemma_div_plus" ]
[]
true
false
true
false
false
let lemma_get_carry_from_bn_add r c =
Math.Lemmas.lemma_div_plus r c (pow2 256); Math.Lemmas.small_div r (pow2 256)
false
Target.fsti
Target.mk_expr
val mk_expr : e: Target.expr' -> Target.expr' * (Ast.pos * Ast.pos)
let mk_expr (e:expr') = e, A.dummy_range
{ "file_name": "src/3d/Target.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 40, "end_line": 66, "start_col": 0, "start_line": 66 }
(* Copyright 2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding /// The same as A.op, but with `SizeOf` removed /// and arithmetic operators resolved to their types type op = | Eq | Neq | And | Or | Not | Plus of A.integer_type | Minus of A.integer_type | Mul of A.integer_type | Division of A.integer_type | Remainder of A.integer_type | BitwiseAnd of A.integer_type | BitwiseXor of A.integer_type | BitwiseOr of A.integer_type | BitwiseNot of A.integer_type | ShiftRight of A.integer_type | ShiftLeft of A.integer_type | LT of A.integer_type | GT of A.integer_type | LE of A.integer_type | GE of A.integer_type | IfThenElse | BitFieldOf: size: int -> order: A.bitfield_bit_order -> op //BitFieldOf(i, from, to) | Cast : from:A.integer_type -> to:A.integer_type -> op | Ext of string /// Same as A.expr, but with `This` removed /// /// Carrying around the range information from AST.expr so that we /// can report errors in terms of their 3d file locations noeq type expr' = | Constant : c:A.constant -> expr' | Identifier : i:A.ident -> expr' | App : hd:op -> args:list expr -> expr' | Record : type_name:A.ident -> list (A.ident * expr) -> expr' and expr = expr' & A.range let subst = list (A.ident' & expr)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": false, "source_file": "Target.fsti" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: Target.expr' -> Target.expr' * (Ast.pos * Ast.pos)
Prims.Tot
[ "total" ]
[]
[ "Target.expr'", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "Ast.pos", "Ast.dummy_range" ]
[]
false
false
false
true
false
let mk_expr (e: expr') =
e, A.dummy_range
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.va_wp_sound_code_norm
val va_wp_sound_code_norm (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) : Ghost (va_state & fuel & a) (t_require s0 /\ normal (wp_sound_code_pre qc s0 k)) (wp_sound_code_post qc s0 k)
val va_wp_sound_code_norm (#a:Type0) (c:code) (qc:quickCode a c) (s0:va_state) (k:(s0':va_state{s0 == s0'}) -> va_state -> a -> Type0) : Ghost (va_state & fuel & a) (t_require s0 /\ normal (wp_sound_code_pre qc s0 k)) (wp_sound_code_post qc s0 k)
let va_wp_sound_code_norm #a c qc s0 k = assert_normal (wp_sound_code_pre qc s0 k); wp_sound_code_wrap c qc s0 k
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 349, "start_col": 0, "start_line": 347 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) ) let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) let rec qWhile_proof_rec (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:state -> a -> Type0) (dec:state -> a -> d) (s0 s1:state) (g1:a) (f1:fuel) (k:state -> a -> Type0) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2 ) (decreases (dec s1 g1)) = let ob = cmp_to_ocmp b in let s1' = {s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b)} in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then ( let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let (s2, f2) = va_lemma_whileTrue_total ob c s0 s1 f1 in let (sc, fc, gc) = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k ) else ( let (s2, f2) = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1) ) let qWhile_proof #a #d #c b qc mods inv dec g0 s0 k = let ob = cmp_to_ocmp b in let (s1, f1) = va_lemma_while_total ob c s0 in update_state_mods_refl mods s0; qWhile_proof_rec b qc mods inv dec s0 s1 g0 f1 k let qAssertLemma p = fun () -> () let qAssumeLemma p = fun () -> assume p let qAssertSquashLemma p = fun () -> () //let qAssertByLemma #a p qcs mods s0 = // fun () -> let _ = wp_sound [] qcs mods (fun _ _ -> p) s0 in () let wp_sound_code #a c qc k s0 = let QProc c _ wp proof = qc in proof s0 k let lemma_state_match s0 s1 = () let wp_sound_code_wrap (#a:Type0) (c:code) (qc:quickCode a c) (s0:state) (k:(s0':state{s0 == s0'}) -> state -> a -> Type0) : Ghost (state & fuel & a) (t_require s0 /\ wp_sound_code_pre qc s0 k) (wp_sound_code_post qc s0 k) = wp_sound_code c qc (k s0) s0 let assert_normal (p:Type) : Lemma (requires normal p) (ensures p) = ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.PPC64LE.QuickCodes.code -> qc: Vale.PPC64LE.QuickCode.quickCode a c -> s0: Vale.PPC64LE.Decls.va_state -> k: (s0': Vale.PPC64LE.Decls.va_state{s0 == s0'} -> _: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> Prims.Ghost ((Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.QuickCodes.fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.code", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.Decls.va_state", "Prims.eq2", "Vale.PPC64LE.QuickCodes.wp_sound_code_wrap", "Prims.unit", "Vale.PPC64LE.QuickCodes.assert_normal", "Vale.PPC64LE.QuickCodes.wp_sound_code_pre", "FStar.Pervasives.Native.tuple3", "Vale.PPC64LE.QuickCodes.fuel" ]
[]
false
false
false
false
false
let va_wp_sound_code_norm #a c qc s0 k =
assert_normal (wp_sound_code_pre qc s0 k); wp_sound_code_wrap c qc s0 k
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.lemma_check_overflow
val lemma_check_overflow: b:nat{b < pow2 256} -> Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in overflow = (if b < S.q then 0 else 1))
val lemma_check_overflow: b:nat{b < pow2 256} -> Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in overflow = (if b < S.q then 0 else 1))
let lemma_check_overflow b = let overflow = (b + (pow2 256 - S.q)) / pow2 256 in if b < S.q then begin assert (pow2 256 + b - S.q < pow2 256); assert (pow2 256 - S.q <= pow2 256 + b - S.q); assert_norm (0 < pow2 256 - S.q); Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256); assert (overflow = 0) end else begin assert (pow2 256 <= pow2 256 + b - S.q); Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256); Math.Lemmas.cancel_mul_div 1 (pow2 256); assert (1 <= overflow); assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q); assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1); Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256); assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1); assert (overflow <= 1) end
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 105, "start_col": 0, "start_line": 87 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2)) let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2) val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2)) let is_qelem_eq_vartime4_lemma f1 f2 = if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2 #pop-options val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128)) let is_qelem_lt_pow2_128_vartime4_lemma f = let (f0, f1, f2, f3) = f in assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192); assert (v f0 + v f1 * pow2 64 < pow2 128); if v f2 = 0 && v f3 = 0 then () else begin Math.Lemmas.pow2_lt_compat 192 128; assert (pow2 128 <= qas_nat4 f) end val lemma_check_overflow: b:nat{b < pow2 256} -> Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in overflow = (if b < S.q then 0 else 1))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.nat{b < Prims.pow2 256} -> FStar.Pervasives.Lemma (ensures (let overflow = (b + (Prims.pow2 256 - Spec.K256.PointOps.q)) / Prims.pow2 256 in overflow = (match b < Spec.K256.PointOps.q with | true -> 0 | _ -> 1)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Spec.K256.PointOps.q", "Prims._assert", "Prims.op_Equality", "Prims.int", "Prims.unit", "FStar.Math.Lemmas.small_div", "Prims.op_Subtraction", "Prims.op_Addition", "FStar.Pervasives.assert_norm", "Prims.op_LessThanOrEqual", "Prims.bool", "Prims.op_Division", "FStar.Math.Lemmas.lemma_div_le", "FStar.Math.Lemmas.cancel_mul_div" ]
[]
false
false
true
false
false
let lemma_check_overflow b =
let overflow = (b + (pow2 256 - S.q)) / pow2 256 in if b < S.q then (assert (pow2 256 + b - S.q < pow2 256); assert (pow2 256 - S.q <= pow2 256 + b - S.q); assert_norm (0 < pow2 256 - S.q); Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256); assert (overflow = 0)) else (assert (pow2 256 <= pow2 256 + b - S.q); Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256); Math.Lemmas.cancel_mul_div 1 (pow2 256); assert (1 <= overflow); assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q); assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1); Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256); assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1); assert (overflow <= 1))
false
Target.fsti
Target.subst
val subst : Type0
let subst = list (A.ident' & expr)
{ "file_name": "src/3d/Target.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 34, "end_line": 64, "start_col": 0, "start_line": 64 }
(* Copyright 2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding /// The same as A.op, but with `SizeOf` removed /// and arithmetic operators resolved to their types type op = | Eq | Neq | And | Or | Not | Plus of A.integer_type | Minus of A.integer_type | Mul of A.integer_type | Division of A.integer_type | Remainder of A.integer_type | BitwiseAnd of A.integer_type | BitwiseXor of A.integer_type | BitwiseOr of A.integer_type | BitwiseNot of A.integer_type | ShiftRight of A.integer_type | ShiftLeft of A.integer_type | LT of A.integer_type | GT of A.integer_type | LE of A.integer_type | GE of A.integer_type | IfThenElse | BitFieldOf: size: int -> order: A.bitfield_bit_order -> op //BitFieldOf(i, from, to) | Cast : from:A.integer_type -> to:A.integer_type -> op | Ext of string /// Same as A.expr, but with `This` removed /// /// Carrying around the range information from AST.expr so that we /// can report errors in terms of their 3d file locations noeq type expr' = | Constant : c:A.constant -> expr' | Identifier : i:A.ident -> expr' | App : hd:op -> args:list expr -> expr' | Record : type_name:A.ident -> list (A.ident * expr) -> expr' and expr = expr' & A.range
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": false, "source_file": "Target.fsti" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "FStar.Pervasives.Native.tuple2", "Ast.ident'", "Target.expr" ]
[]
false
false
false
true
true
let subst =
list (A.ident' & expr)
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.update_state_mods_to1
val update_state_mods_to1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s))
val update_state_mods_to1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s))
let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 67, "start_col": 0, "start_line": 56 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mods: Vale.PPC64LE.QuickCode.mods_t -> s': Vale.PPC64LE.State.state -> s: Vale.PPC64LE.State.state -> m0: Vale.PPC64LE.QuickCode.mod_t -> FStar.Pervasives.Lemma (requires Vale.PPC64LE.QuickCodes.mods_contains1 mods m0 \/ Vale.PPC64LE.QuickCodes.state_mod_eq m0 s s') (ensures Vale.PPC64LE.QuickCodes.state_mod_eq m0 s' (Vale.PPC64LE.QuickCode.update_state_mods mods s' s))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCode.mod_t", "Prims.list", "FStar.Classical.or_elim", "Prims.l_not", "Prims.squash", "Prims.unit", "Prims.l_True", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.PPC64LE.QuickCodes.update_state_mods_to1", "Prims.l_or", "Vale.PPC64LE.QuickCodes.state_mod_eq", "Vale.PPC64LE.QuickCode.update_state_mods", "Prims.logical", "Prims.eq2", "Prims.b2t", "Vale.PPC64LE.QuickCodes.mods_contains1" ]
[ "recursion" ]
false
false
true
false
false
let rec update_state_mods_to1 (mods: mods_t) (s' s: state) (m0: mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) =
match mods with | [] -> () | r :: mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_: squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_: squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_: squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2
false
Target.fsti
Target.field_typ
val field_typ : Type0
let field_typ = typ
{ "file_name": "src/3d/Target.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 19, "end_line": 110, "start_col": 0, "start_line": 110 }
(* Copyright 2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding /// The same as A.op, but with `SizeOf` removed /// and arithmetic operators resolved to their types type op = | Eq | Neq | And | Or | Not | Plus of A.integer_type | Minus of A.integer_type | Mul of A.integer_type | Division of A.integer_type | Remainder of A.integer_type | BitwiseAnd of A.integer_type | BitwiseXor of A.integer_type | BitwiseOr of A.integer_type | BitwiseNot of A.integer_type | ShiftRight of A.integer_type | ShiftLeft of A.integer_type | LT of A.integer_type | GT of A.integer_type | LE of A.integer_type | GE of A.integer_type | IfThenElse | BitFieldOf: size: int -> order: A.bitfield_bit_order -> op //BitFieldOf(i, from, to) | Cast : from:A.integer_type -> to:A.integer_type -> op | Ext of string /// Same as A.expr, but with `This` removed /// /// Carrying around the range information from AST.expr so that we /// can report errors in terms of their 3d file locations noeq type expr' = | Constant : c:A.constant -> expr' | Identifier : i:A.ident -> expr' | App : hd:op -> args:list expr -> expr' | Record : type_name:A.ident -> list (A.ident * expr) -> expr' and expr = expr' & A.range let subst = list (A.ident' & expr) val subst_expr (s:subst) (e:expr) : expr let mk_expr (e:expr') = e, A.dummy_range type lam a = (option A.ident) & a noeq type atomic_action = | Action_return of expr | Action_abort | Action_field_pos_64 | Action_field_pos_32 | Action_field_ptr | Action_field_ptr_after: sz: expr -> write_to:A.ident -> atomic_action | Action_field_ptr_after_with_setter: sz: expr -> write_to_field:A.ident -> write_to_object:expr -> atomic_action | Action_deref of A.ident | Action_assignment : lhs:A.ident -> rhs:expr -> atomic_action | Action_call : f:A.ident -> args:list expr -> atomic_action noeq type action = | Atomic_action of atomic_action | Action_seq : hd:atomic_action -> tl:action -> action | Action_ite : hd:expr -> then_:action -> else_:action -> action | Action_let : i:A.ident -> a:atomic_action -> k:action -> action | Action_act : action -> action (* A subset of F* types that the translation targets *) noeq type typ = | T_false : typ | T_app : hd:A.ident -> A.t_kind -> args:list index -> typ | T_dep_pair : dfst:typ -> dsnd:(A.ident & typ) -> typ | T_refine : base:typ -> refinement:lam expr -> typ | T_if_else : e:expr -> t:typ -> f:typ -> typ | T_pointer : typ -> typ | T_with_action: typ -> action -> typ | T_with_dep_action: typ -> a:lam action -> typ | T_with_comment: typ -> A.comments -> typ | T_with_probe: typ -> probe_fn:A.ident -> len:expr -> dest:A.ident -> typ (* An index is an F* type or an expression -- we reuse Ast expressions for this *) and index = either typ expr
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": false, "source_file": "Target.fsti" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Target.typ" ]
[]
false
false
false
true
true
let field_typ =
typ
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.wp_sound_code
val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN)
val wp_sound_code (#a:Type0) (c:code) (qc:quickCode a c) (k:va_state -> a -> Type0) (s0:va_state) : Ghost (va_state & fuel & a) (requires t_require s0 /\ QProc?.wp qc s0 k) (ensures fun (sN, fN, gN) -> eval_code c s0 fN sN /\ update_state_mods qc.mods sN s0 == sN /\ state_inv sN /\ k sN gN)
let wp_sound_code #a c qc k s0 = let QProc c _ wp proof = qc in proof s0 k
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 12, "end_line": 329, "start_col": 0, "start_line": 327 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) ) let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) let rec qWhile_proof_rec (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:state -> a -> Type0) (dec:state -> a -> d) (s0 s1:state) (g1:a) (f1:fuel) (k:state -> a -> Type0) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2 ) (decreases (dec s1 g1)) = let ob = cmp_to_ocmp b in let s1' = {s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b)} in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then ( let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let (s2, f2) = va_lemma_whileTrue_total ob c s0 s1 f1 in let (sc, fc, gc) = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k ) else ( let (s2, f2) = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1) ) let qWhile_proof #a #d #c b qc mods inv dec g0 s0 k = let ob = cmp_to_ocmp b in let (s1, f1) = va_lemma_while_total ob c s0 in update_state_mods_refl mods s0; qWhile_proof_rec b qc mods inv dec s0 s1 g0 f1 k let qAssertLemma p = fun () -> () let qAssumeLemma p = fun () -> assume p let qAssertSquashLemma p = fun () -> () //let qAssertByLemma #a p qcs mods s0 = // fun () -> let _ = wp_sound [] qcs mods (fun _ _ -> p) s0 in ()
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Vale.PPC64LE.QuickCodes.code -> qc: Vale.PPC64LE.QuickCode.quickCode a c -> k: (_: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> s0: Vale.PPC64LE.Decls.va_state -> Prims.Ghost ((Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.QuickCodes.fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.code", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.Decls.va_state", "Vale.PPC64LE.Decls.va_code", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.QuickCode.quickProc_wp", "Vale.PPC64LE.QuickCode.t_proof", "FStar.Pervasives.Native.tuple3", "Vale.PPC64LE.QuickCodes.fuel" ]
[]
false
false
false
false
false
let wp_sound_code #a c qc k s0 =
let QProc c _ wp proof = qc in proof s0 k
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.qInlineIf_proof
val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
val qInlineIf_proof (#a:Type) (#c1:code) (#c2:code) (b:bool) (qc1:quickCode a c1) (qc2:quickCode a c2) (mods:mods_t) (s0:va_state) (k:va_state -> a -> Type0) : Ghost (va_state & va_fuel & a) (requires t_require s0 /\ wp_InlineIf b qc1 qc2 mods s0 k) (ensures fun (sM, f0, g) -> eval_code (if_code b c1 c2) s0 f0 sM /\ update_state_mods mods sM s0 == sM /\ state_inv sM /\ k sM g )
let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) )
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 248, "start_col": 0, "start_line": 236 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> qc1: Vale.PPC64LE.QuickCode.quickCode a c1 -> qc2: Vale.PPC64LE.QuickCode.quickCode a c2 -> mods: Vale.PPC64LE.QuickCode.mods_t -> s0: Vale.PPC64LE.Decls.va_state -> k: (_: Vale.PPC64LE.Decls.va_state -> _: a -> Type0) -> Prims.Ghost ((Vale.PPC64LE.Decls.va_state * Vale.PPC64LE.Decls.va_fuel) * a)
Prims.Ghost
[]
[]
[ "Vale.PPC64LE.QuickCodes.code", "Prims.bool", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.Decls.va_state", "Vale.PPC64LE.State.state", "Vale.PPC64LE.Decls.va_fuel", "FStar.Pervasives.Native.Mktuple3", "Prims.unit", "Vale.PPC64LE.QuickCodes.update_state_mods_weaken", "Vale.PPC64LE.QuickCode.__proj__QProc__item__mods", "FStar.Pervasives.Native.tuple3", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.QuickCode.__proj__QProc__item__proof" ]
[]
false
false
false
false
false
let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k =
if b then (let sM, f0, g = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g)) else (let sM, f0, g = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g))
false
Target.fsti
Target.assumption
val assumption : Type0
let assumption = A.ident * typ
{ "file_name": "src/3d/Target.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 30, "end_line": 222, "start_col": 0, "start_line": 222 }
(* Copyright 2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding /// The same as A.op, but with `SizeOf` removed /// and arithmetic operators resolved to their types type op = | Eq | Neq | And | Or | Not | Plus of A.integer_type | Minus of A.integer_type | Mul of A.integer_type | Division of A.integer_type | Remainder of A.integer_type | BitwiseAnd of A.integer_type | BitwiseXor of A.integer_type | BitwiseOr of A.integer_type | BitwiseNot of A.integer_type | ShiftRight of A.integer_type | ShiftLeft of A.integer_type | LT of A.integer_type | GT of A.integer_type | LE of A.integer_type | GE of A.integer_type | IfThenElse | BitFieldOf: size: int -> order: A.bitfield_bit_order -> op //BitFieldOf(i, from, to) | Cast : from:A.integer_type -> to:A.integer_type -> op | Ext of string /// Same as A.expr, but with `This` removed /// /// Carrying around the range information from AST.expr so that we /// can report errors in terms of their 3d file locations noeq type expr' = | Constant : c:A.constant -> expr' | Identifier : i:A.ident -> expr' | App : hd:op -> args:list expr -> expr' | Record : type_name:A.ident -> list (A.ident * expr) -> expr' and expr = expr' & A.range let subst = list (A.ident' & expr) val subst_expr (s:subst) (e:expr) : expr let mk_expr (e:expr') = e, A.dummy_range type lam a = (option A.ident) & a noeq type atomic_action = | Action_return of expr | Action_abort | Action_field_pos_64 | Action_field_pos_32 | Action_field_ptr | Action_field_ptr_after: sz: expr -> write_to:A.ident -> atomic_action | Action_field_ptr_after_with_setter: sz: expr -> write_to_field:A.ident -> write_to_object:expr -> atomic_action | Action_deref of A.ident | Action_assignment : lhs:A.ident -> rhs:expr -> atomic_action | Action_call : f:A.ident -> args:list expr -> atomic_action noeq type action = | Atomic_action of atomic_action | Action_seq : hd:atomic_action -> tl:action -> action | Action_ite : hd:expr -> then_:action -> else_:action -> action | Action_let : i:A.ident -> a:atomic_action -> k:action -> action | Action_act : action -> action (* A subset of F* types that the translation targets *) noeq type typ = | T_false : typ | T_app : hd:A.ident -> A.t_kind -> args:list index -> typ | T_dep_pair : dfst:typ -> dsnd:(A.ident & typ) -> typ | T_refine : base:typ -> refinement:lam expr -> typ | T_if_else : e:expr -> t:typ -> f:typ -> typ | T_pointer : typ -> typ | T_with_action: typ -> action -> typ | T_with_dep_action: typ -> a:lam action -> typ | T_with_comment: typ -> A.comments -> typ | T_with_probe: typ -> probe_fn:A.ident -> len:expr -> dest:A.ident -> typ (* An index is an F* type or an expression -- we reuse Ast expressions for this *) and index = either typ expr let field_typ = typ type param = A.ident & typ let mk_subst (l:list param) (args:list expr) : ML (option subst) = if List.Tot.length l <> List.Tot.length args then None else ( Some (List.map2 #param (fun (i, t) e -> i.v, e) l args) ) noeq type struct_field = { sf_dependence: bool; sf_ident: A.ident; sf_typ: field_typ } type field = struct_field noeq type typedef_body = | TD_abbrev : typ -> typedef_body | TD_struct : list field -> typedef_body noeq type typedef_name = { td_name:A.ident; td_params:list param; td_entrypoint:bool } type typedef = typedef_name & typedef_body //////////////////////////////////////////////////////////////////////////////// noeq type parser_kind' = | PK_return | PK_impos | PK_base : hd:A.ident -> parser_kind' | PK_list : parser_kind' | PK_t_at_most: parser_kind' | PK_t_exact : parser_kind' | PK_filter : k:parser_kind -> parser_kind' | PK_and_then : k1:parser_kind -> k2:parser_kind -> parser_kind' | PK_glb : k1:parser_kind -> k2:parser_kind -> parser_kind' | PK_string : parser_kind' and parser_kind = { pk_kind : parser_kind'; pk_weak_kind : A.weak_kind ; pk_nz: bool } val expr_eq (e1 e1:expr) : bool val exprs_eq (es1 es1:list expr) : bool val fields_eq (fs1 fs2:list (A.ident & expr)) : bool val parser_kind_eq (k k':parser_kind) : bool noeq type parser' = | Parse_return : v:expr -> parser' | Parse_app : hd:A.ident -> args:list index -> parser' | Parse_nlist : n:expr -> t:parser -> parser' | Parse_t_at_most : n:expr -> t:parser -> parser' | Parse_t_exact : n:expr -> t:parser -> parser' | Parse_pair : n1: A.ident -> p:parser -> q:parser -> parser' | Parse_dep_pair : n1: A.ident -> p:parser -> k:lam parser -> parser' | Parse_dep_pair_with_refinement: n1: A.ident -> dfst:parser -> refinement:lam expr -> dsnd:lam parser -> parser' | Parse_dep_pair_with_action: dfst:parser -> a:lam action -> dsnd:lam parser -> parser' | Parse_dep_pair_with_refinement_and_action: n1: A.ident -> dfst:parser -> refinement:lam expr -> a:lam action -> dsnd:lam parser -> parser' | Parse_map : p:parser -> f:lam expr -> parser' | Parse_refinement: n:A.ident -> p:parser -> f:lam expr -> parser' | Parse_refinement_with_action : n:A.ident -> p:parser -> f:lam expr -> a:lam action -> parser' | Parse_with_dep_action : name:A.ident -> p:parser -> a:lam action -> parser' | Parse_with_action: name: A.ident -> p:parser -> a:action -> parser' | Parse_weaken_left: p:parser -> k:parser_kind -> parser' | Parse_weaken_right: p:parser -> k:parser_kind -> parser' | Parse_if_else : e:expr -> parser -> parser -> parser' | Parse_impos : parser' | Parse_with_comment: p:parser -> c:A.comments -> parser' | Parse_string : p:parser -> zero:expr -> parser' | Parse_with_probe : p:parser -> probe:A.ident -> len:expr -> dest:A.ident -> parser' and parser = { p_kind:parser_kind; p_typ:typ; p_parser:parser'; p_typename: A.ident; p_fieldname: string; } noeq type reader = | Read_u8 | Read_u16 | Read_u32 | Read_filter : r:reader -> f:lam expr -> reader | Read_app : hd:A.ident -> args:list index -> reader //////////////////////////////////////////////////////////////////////////////// noeq type type_decl = { decl_name: typedef_name; decl_typ: typedef_body; decl_parser: parser; decl_is_enum : bool } let definition = A.ident * list param * typ * expr
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": false, "source_file": "Target.fsti" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "Ast.ident", "Target.typ" ]
[]
false
false
false
true
true
let assumption =
A.ident * typ
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.is_qelem_lt_pow2_128_vartime4_lemma
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
let is_qelem_lt_pow2_128_vartime4_lemma f = let (f0, f1, f2, f3) = f in assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192); assert (v f0 + v f1 * pow2 64 < pow2 128); if v f2 = 0 && v f3 = 0 then () else begin Math.Lemmas.pow2_lt_compat 192 128; assert (pow2 128 <= qas_nat4 f) end
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 80, "start_col": 0, "start_line": 73 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2)) let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2) val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2)) let is_qelem_eq_vartime4_lemma f1 f2 = if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2 #pop-options val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Spec.K256.Scalar.qelem4 -> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Scalar.is_qelem_lt_pow2_128_vartime4 f == (Hacl.Spec.K256.Scalar.qas_nat4 f < Prims.pow2 128))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem4", "Lib.IntTypes.uint64", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.bool", "Prims._assert", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.pow2", "Hacl.Spec.K256.Scalar.qas_nat4", "Prims.unit", "FStar.Math.Lemmas.pow2_lt_compat", "Prims.op_LessThan", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.eq2" ]
[]
false
false
true
false
false
let is_qelem_lt_pow2_128_vartime4_lemma f =
let f0, f1, f2, f3 = f in assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192); assert (v f0 + v f1 * pow2 64 < pow2 128); if v f2 = 0 && v f3 = 0 then () else (Math.Lemmas.pow2_lt_compat 192 128; assert (pow2 128 <= qas_nat4 f))
false
Hacl.Spec.Curve25519.Finv.fst
Hacl.Spec.Curve25519.Finv.pow
val pow : x: Spec.Curve25519.elem -> b: Prims.nat -> Spec.Curve25519.elem
let pow = fpow
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 11, "start_col": 0, "start_line": 11 }
module Hacl.Spec.Curve25519.Finv open FStar.Mul open Spec.Curve25519 module M = Lib.NatMod module LE = Lib.Exponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Spec.Curve25519.elem -> b: Prims.nat -> Spec.Curve25519.elem
Prims.Tot
[ "total" ]
[]
[ "Spec.Curve25519.fpow" ]
[]
false
false
false
true
false
let pow =
fpow
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.is_qelem_eq_vartime4_lemma
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2))
let is_qelem_eq_vartime4_lemma f1 f2 = if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 66, "start_col": 0, "start_line": 65 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2)) let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2) val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 ->
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.K256.Scalar.qelem4 -> f2: Hacl.Spec.K256.Scalar.qelem4 -> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Scalar.is_qelem_eq_vartime4 f1 f2 == (Hacl.Spec.K256.Scalar.qas_nat4 f1 = Hacl.Spec.K256.Scalar.qas_nat4 f2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem4", "Prims.op_Equality", "Prims.int", "Hacl.Spec.K256.Scalar.qas_nat4", "Hacl.Spec.K256.Scalar.Lemmas.qas_nat4_inj", "Prims.bool", "Prims.unit" ]
[]
false
false
true
false
false
let is_qelem_eq_vartime4_lemma f1 f2 =
if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2
false
Hacl.Spec.Curve25519.Finv.fst
Hacl.Spec.Curve25519.Finv.cm_prime
val cm_prime : Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.Curve25519.prime)
let cm_prime = M.mk_nat_mod_comm_monoid prime
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 12, "start_col": 0, "start_line": 12 }
module Hacl.Spec.Curve25519.Finv open FStar.Mul open Spec.Curve25519 module M = Lib.NatMod module LE = Lib.Exponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let fsqr x = fmul x x
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.Curve25519.prime)
Prims.Tot
[ "total" ]
[]
[ "Lib.NatMod.mk_nat_mod_comm_monoid", "Spec.Curve25519.prime" ]
[]
false
false
false
true
false
let cm_prime =
M.mk_nat_mod_comm_monoid prime
false
Hacl.Spec.Curve25519.Finv.fst
Hacl.Spec.Curve25519.Finv.fsqr
val fsqr : x: Spec.Curve25519.elem -> Spec.Curve25519.elem
let fsqr x = fmul x x
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 10, "start_col": 0, "start_line": 10 }
module Hacl.Spec.Curve25519.Finv open FStar.Mul open Spec.Curve25519 module M = Lib.NatMod module LE = Lib.Exponentiation #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Spec.Curve25519.elem -> Spec.Curve25519.elem
Prims.Tot
[ "total" ]
[]
[ "Spec.Curve25519.elem", "Spec.Curve25519.fmul" ]
[]
false
false
false
true
false
let fsqr x =
fmul x x
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.is_qelem_lt_q_vartime4_lemma
val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q))
let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 55, "start_col": 0, "start_line": 53 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 ->
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Spec.K256.Scalar.qelem4 -> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Scalar.is_qelem_lt_q_vartime4 f == (Hacl.Spec.K256.Scalar.qas_nat4 f < Spec.K256.PointOps.q))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem4", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "Spec.K256.PointOps.q", "Prims.unit" ]
[]
true
false
true
false
false
let is_qelem_lt_q_vartime4_lemma f =
assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q)
false
Target.fsti
Target.definition
val definition : Type0
let definition = A.ident * list param * typ * expr
{ "file_name": "src/3d/Target.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 50, "end_line": 220, "start_col": 0, "start_line": 220 }
(* Copyright 2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Target (* The abstract syntax for the code produced by 3d *) open FStar.All module A = Ast open Binding /// The same as A.op, but with `SizeOf` removed /// and arithmetic operators resolved to their types type op = | Eq | Neq | And | Or | Not | Plus of A.integer_type | Minus of A.integer_type | Mul of A.integer_type | Division of A.integer_type | Remainder of A.integer_type | BitwiseAnd of A.integer_type | BitwiseXor of A.integer_type | BitwiseOr of A.integer_type | BitwiseNot of A.integer_type | ShiftRight of A.integer_type | ShiftLeft of A.integer_type | LT of A.integer_type | GT of A.integer_type | LE of A.integer_type | GE of A.integer_type | IfThenElse | BitFieldOf: size: int -> order: A.bitfield_bit_order -> op //BitFieldOf(i, from, to) | Cast : from:A.integer_type -> to:A.integer_type -> op | Ext of string /// Same as A.expr, but with `This` removed /// /// Carrying around the range information from AST.expr so that we /// can report errors in terms of their 3d file locations noeq type expr' = | Constant : c:A.constant -> expr' | Identifier : i:A.ident -> expr' | App : hd:op -> args:list expr -> expr' | Record : type_name:A.ident -> list (A.ident * expr) -> expr' and expr = expr' & A.range let subst = list (A.ident' & expr) val subst_expr (s:subst) (e:expr) : expr let mk_expr (e:expr') = e, A.dummy_range type lam a = (option A.ident) & a noeq type atomic_action = | Action_return of expr | Action_abort | Action_field_pos_64 | Action_field_pos_32 | Action_field_ptr | Action_field_ptr_after: sz: expr -> write_to:A.ident -> atomic_action | Action_field_ptr_after_with_setter: sz: expr -> write_to_field:A.ident -> write_to_object:expr -> atomic_action | Action_deref of A.ident | Action_assignment : lhs:A.ident -> rhs:expr -> atomic_action | Action_call : f:A.ident -> args:list expr -> atomic_action noeq type action = | Atomic_action of atomic_action | Action_seq : hd:atomic_action -> tl:action -> action | Action_ite : hd:expr -> then_:action -> else_:action -> action | Action_let : i:A.ident -> a:atomic_action -> k:action -> action | Action_act : action -> action (* A subset of F* types that the translation targets *) noeq type typ = | T_false : typ | T_app : hd:A.ident -> A.t_kind -> args:list index -> typ | T_dep_pair : dfst:typ -> dsnd:(A.ident & typ) -> typ | T_refine : base:typ -> refinement:lam expr -> typ | T_if_else : e:expr -> t:typ -> f:typ -> typ | T_pointer : typ -> typ | T_with_action: typ -> action -> typ | T_with_dep_action: typ -> a:lam action -> typ | T_with_comment: typ -> A.comments -> typ | T_with_probe: typ -> probe_fn:A.ident -> len:expr -> dest:A.ident -> typ (* An index is an F* type or an expression -- we reuse Ast expressions for this *) and index = either typ expr let field_typ = typ type param = A.ident & typ let mk_subst (l:list param) (args:list expr) : ML (option subst) = if List.Tot.length l <> List.Tot.length args then None else ( Some (List.map2 #param (fun (i, t) e -> i.v, e) l args) ) noeq type struct_field = { sf_dependence: bool; sf_ident: A.ident; sf_typ: field_typ } type field = struct_field noeq type typedef_body = | TD_abbrev : typ -> typedef_body | TD_struct : list field -> typedef_body noeq type typedef_name = { td_name:A.ident; td_params:list param; td_entrypoint:bool } type typedef = typedef_name & typedef_body //////////////////////////////////////////////////////////////////////////////// noeq type parser_kind' = | PK_return | PK_impos | PK_base : hd:A.ident -> parser_kind' | PK_list : parser_kind' | PK_t_at_most: parser_kind' | PK_t_exact : parser_kind' | PK_filter : k:parser_kind -> parser_kind' | PK_and_then : k1:parser_kind -> k2:parser_kind -> parser_kind' | PK_glb : k1:parser_kind -> k2:parser_kind -> parser_kind' | PK_string : parser_kind' and parser_kind = { pk_kind : parser_kind'; pk_weak_kind : A.weak_kind ; pk_nz: bool } val expr_eq (e1 e1:expr) : bool val exprs_eq (es1 es1:list expr) : bool val fields_eq (fs1 fs2:list (A.ident & expr)) : bool val parser_kind_eq (k k':parser_kind) : bool noeq type parser' = | Parse_return : v:expr -> parser' | Parse_app : hd:A.ident -> args:list index -> parser' | Parse_nlist : n:expr -> t:parser -> parser' | Parse_t_at_most : n:expr -> t:parser -> parser' | Parse_t_exact : n:expr -> t:parser -> parser' | Parse_pair : n1: A.ident -> p:parser -> q:parser -> parser' | Parse_dep_pair : n1: A.ident -> p:parser -> k:lam parser -> parser' | Parse_dep_pair_with_refinement: n1: A.ident -> dfst:parser -> refinement:lam expr -> dsnd:lam parser -> parser' | Parse_dep_pair_with_action: dfst:parser -> a:lam action -> dsnd:lam parser -> parser' | Parse_dep_pair_with_refinement_and_action: n1: A.ident -> dfst:parser -> refinement:lam expr -> a:lam action -> dsnd:lam parser -> parser' | Parse_map : p:parser -> f:lam expr -> parser' | Parse_refinement: n:A.ident -> p:parser -> f:lam expr -> parser' | Parse_refinement_with_action : n:A.ident -> p:parser -> f:lam expr -> a:lam action -> parser' | Parse_with_dep_action : name:A.ident -> p:parser -> a:lam action -> parser' | Parse_with_action: name: A.ident -> p:parser -> a:action -> parser' | Parse_weaken_left: p:parser -> k:parser_kind -> parser' | Parse_weaken_right: p:parser -> k:parser_kind -> parser' | Parse_if_else : e:expr -> parser -> parser -> parser' | Parse_impos : parser' | Parse_with_comment: p:parser -> c:A.comments -> parser' | Parse_string : p:parser -> zero:expr -> parser' | Parse_with_probe : p:parser -> probe:A.ident -> len:expr -> dest:A.ident -> parser' and parser = { p_kind:parser_kind; p_typ:typ; p_parser:parser'; p_typename: A.ident; p_fieldname: string; } noeq type reader = | Read_u8 | Read_u16 | Read_u32 | Read_filter : r:reader -> f:lam expr -> reader | Read_app : hd:A.ident -> args:list index -> reader //////////////////////////////////////////////////////////////////////////////// noeq type type_decl = { decl_name: typedef_name; decl_typ: typedef_body; decl_parser: parser; decl_is_enum : bool }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.All.fst.checked", "Binding.fsti.checked", "Ast.fst.checked" ], "interface_file": false, "source_file": "Target.fsti" }
[ { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple4", "Ast.ident", "Prims.list", "Target.param", "Target.typ", "Target.expr" ]
[]
false
false
false
true
true
let definition =
((A.ident * list param) * typ) * expr
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.mul_pow2_256_minus_q_lt_lemma
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} -> Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} -> Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
let mul_pow2_256_minus_q_lt_lemma p a = Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p); assert_norm (pow2 256 - S.q < pow2 129); Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129); Math.Lemmas.pow2_plus p 129
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 203, "start_col": 0, "start_line": 199 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2)) let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2) val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2)) let is_qelem_eq_vartime4_lemma f1 f2 = if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2 #pop-options val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128)) let is_qelem_lt_pow2_128_vartime4_lemma f = let (f0, f1, f2, f3) = f in assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192); assert (v f0 + v f1 * pow2 64 < pow2 128); if v f2 = 0 && v f3 = 0 then () else begin Math.Lemmas.pow2_lt_compat 192 128; assert (pow2 128 <= qas_nat4 f) end val lemma_check_overflow: b:nat{b < pow2 256} -> Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in overflow = (if b < S.q then 0 else 1)) let lemma_check_overflow b = let overflow = (b + (pow2 256 - S.q)) / pow2 256 in if b < S.q then begin assert (pow2 256 + b - S.q < pow2 256); assert (pow2 256 - S.q <= pow2 256 + b - S.q); assert_norm (0 < pow2 256 - S.q); Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256); assert (overflow = 0) end else begin assert (pow2 256 <= pow2 256 + b - S.q); Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256); Math.Lemmas.cancel_mul_div 1 (pow2 256); assert (1 <= overflow); assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q); assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1); Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256); assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1); assert (overflow <= 1) end val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat -> Lemma ((r + c * pow2 256) / pow2 256 = c) let lemma_get_carry_from_bn_add r c = Math.Lemmas.lemma_div_plus r c (pow2 256); Math.Lemmas.small_div r (pow2 256) val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma (requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q) (ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q) let mod_short_lseq_lemma_aux a out c = assert_norm (pow2 256 - S.q < S.q); let mask = u64 0 -. c in let out1 = map2 (BB.mask_select mask) out a in assert (v mask = (if v c = 0 then 0 else ones_v U64)); BB.lseq_mask_select_lemma out a mask; assert (out1 == (if v c = 0 then a else out)); SD.bn_eval_bound a 4; SD.bn_eval_bound out 4; lemma_check_overflow (SD.bn_v a); lemma_get_carry_from_bn_add (SD.bn_v out) (v c); assert (v c = (if SD.bn_v a < S.q then 0 else 1)); if SD.bn_v a < S.q then begin assert (SD.bn_v out1 == SD.bn_v a); Math.Lemmas.small_mod (SD.bn_v a) S.q end else begin assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256); Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1; assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q); Math.Lemmas.small_mod (SD.bn_v out1) S.q end val mod_short_lseq_lemma: a:qelem_lseq -> Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q) let mod_short_lseq_lemma a = let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in let tmp = create4 t0 t1 t2 t3 in let c, out = SB.bn_add a tmp in SB.bn_add_lemma a tmp; assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp); qas_nat4_is_qas_nat tmp; assert (SD.bn_v tmp == pow2 256 - S.q); mod_short_lseq_lemma_aux a out c val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len -> Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q)) let mul_pow2_256_minus_q_lemma len resLen a = let t0 = u64 0x402da1732fc9bebf in let t1 = u64 0x4551231950b75fc4 in assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128); let t01 = create2 t0 t1 in SD.bn_eval_unfold_i t01 2; SD.bn_eval_unfold_i t01 1; SD.bn_eval0 t01; assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128); let m0 = SB.bn_mul a t01 in // a * t01 SB.bn_mul_lemma a t01; assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01); let m10 = create resLen (u64 0) in let m1 = update_sub m10 2 len a in // a * t2 * pow2 128 SD.bn_update_sub_eval m10 a 2; assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128); SD.bn_eval_zeroes #U64 resLen resLen; eq_intro (sub m10 2 len) (create len (u64 0)); SD.bn_eval_zeroes #U64 len len; assert (SD.bn_v m1 = SD.bn_v a * pow2 128); let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C SB.bn_add_lemma m1 m0; assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0); assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01); Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01); assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q)) val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} -> Lemma (a * (pow2 256 - S.q) < pow2 (p + 129))
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Prims.nat -> a: Prims.nat{a < Prims.pow2 p} -> FStar.Pervasives.Lemma (ensures a * (Prims.pow2 256 - Spec.K256.PointOps.q) < Prims.pow2 (p + 129))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Math.Lemmas.pow2_plus", "Prims.unit", "FStar.Math.Lemmas.lemma_mult_lt_left", "Prims.op_Subtraction", "Spec.K256.PointOps.q", "FStar.Pervasives.assert_norm", "FStar.Math.Lemmas.lemma_mult_lt_right" ]
[]
true
false
true
false
false
let mul_pow2_256_minus_q_lt_lemma p a =
Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p); assert_norm (pow2 256 - S.q < pow2 129); Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129); Math.Lemmas.pow2_plus p 129
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_bs_i
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])
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)
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 548, "start_col": 0, "start_line": 541 }
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])
{ "checked_file": "/", "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" }
[ { "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 } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
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.Math.Lemmas.cancel_mul_div w Hacl.Spec.Chacha20.Equiv.blocksize; let b = Lib.Sequence.Lemmas.get_block_s Hacl.Spec.Chacha20.Equiv.blocksize b_v j in Lib.Sequence.div_mul_lt Hacl.Spec.Chacha20.Equiv.blocksize j w; (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 ]))
FStar.Pervasives.Lemma
[ "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" ]
[]
true
false
true
false
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)
false
Vale.PPC64LE.QuickCodes.fst
Vale.PPC64LE.QuickCodes.qWhile_proof_rec
val qWhile_proof_rec (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (state -> a -> Type0)) (dec: (state -> a -> d)) (s0 s1: state) (g1: a) (f1: fuel) (k: (state -> a -> Type0)) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2) (decreases (dec s1 g1))
val qWhile_proof_rec (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (state -> a -> Type0)) (dec: (state -> a -> d)) (s0 s1: state) (g1: a) (f1: fuel) (k: (state -> a -> Type0)) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2) (decreases (dec s1 g1))
let rec qWhile_proof_rec (#a #d:Type) (#c:code) (b:cmp) (qc:a -> quickCode a c) (mods:mods_t) (inv:state -> a -> Type0) (dec:state -> a -> d) (s0 s1:state) (g1:a) (f1:fuel) (k:state -> a -> Type0) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2 ) (decreases (dec s1 g1)) = let ob = cmp_to_ocmp b in let s1' = {s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b)} in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then ( let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let (s2, f2) = va_lemma_whileTrue_total ob c s0 s1 f1 in let (sc, fc, gc) = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k ) else ( let (s2, f2) = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1) )
{ "file_name": "vale/code/arch/ppc64le/Vale.PPC64LE.QuickCodes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 312, "start_col": 0, "start_line": 278 }
module Vale.PPC64LE.QuickCodes open FStar.Mul open FStar.Range open Vale.Arch.HeapImpl module Map16 = Vale.Lib.Map16 friend Vale.PPC64LE.Stack_Sems #reset-options "--initial_ifuel 1 --z3rlimit 30" let lemma_label_Type0 (r:range) (msg:string) (p:Type0) : Lemma (requires True) (ensures label r msg p ==> p) = () let lemma_label_bool r msg b = lemma_label_Type0 r msg b let rec empty_list_is_small #a x = match x with | [] -> () | h::t -> empty_list_is_small t let state_mod_eq (m:mod_t) (s1 s2:state) = match m with | Mod_None -> True | Mod_ok -> s1.ok == s2.ok | Mod_reg r -> eval_reg r s1 == eval_reg r s2 | Mod_vec v -> eval_vec v s1 == eval_vec v s2 | Mod_cr0 -> s1.cr0 == s2.cr0 | Mod_xer -> s1.xer == s2.xer | Mod_mem -> (coerce s1.ms_heap).vf_heap == (coerce s2.ms_heap).vf_heap | Mod_mem_layout -> (coerce s1.ms_heap).vf_layout == (coerce s2.ms_heap).vf_layout | Mod_mem_heaplet n -> Map16.sel (coerce s1.ms_heap).vf_heaplets n == Map16.sel (coerce s2.ms_heap).vf_heaplets n | Mod_stack -> s1.ms_stack == s2.ms_stack | Mod_stackTaint -> s1.ms_stackTaint == s2.ms_stackTaint let rec update_state_mods_refl (mods:mods_t) (s:state) : Lemma (ensures state_eq (update_state_mods mods s s) s) = match mods with | [] -> () | _::mods -> update_state_mods_refl mods s let rec update_state_mods_not1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires not (mods_contains1 mods m0)) (ensures state_mod_eq m0 s (update_state_mods mods s' s)) = match mods with | [] -> () | _::mods -> update_state_mods_not1 mods s' s m0 let update_state_mods_from1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires state_mod_eq m0 s' (update_state_mods mods s' s)) (ensures mods_contains1 mods m0 \/ state_mod_eq m0 s s') = if not (mods_contains1 mods m0) then update_state_mods_not1 mods s' s m0 let rec update_state_mods_to1 (mods:mods_t) (s' s:state) (m0:mod_t) : Lemma (requires mods_contains1 mods m0 \/ state_mod_eq m0 s s') (ensures state_mod_eq m0 s' (update_state_mods mods s' s)) = match mods with | [] -> () | r::mods' -> let b = r =!= m0 \/ state_mod_eq m0 s s' in let goal (_:squash (b \/ ~b)) : Type0 = state_mod_eq m0 s' (update_state_mods mods s' s) in let l1 (_:squash b) : Lemma (goal ()) = update_state_mods_to1 mods' s' s m0 in let l2 (_:squash (~b)) : Lemma (goal ()) = () in FStar.Classical.or_elim #b #(~b) #goal l1 l2 let update_state_mods_from (mods:mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s') (ensures ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) = let f1 (m0:mod_t) : Lemma (mods_contains1 mods m0 \/ state_mod_eq m0 s s') = update_state_mods_from1 mods s' s m0 in FStar.Classical.forall_intro f1 let update_state_mods_to (mods:mods_t) (s' s:state) : Lemma (requires ( forall (m0:mod_t).{:pattern mods_contains1 mods m0 \/ state_mod_eq m0 s s'} mods_contains1 mods m0 \/ state_mod_eq m0 s s' )) (ensures state_eq s' (update_state_mods mods s' s)) = let s'' = update_state_mods mods s' s in let f1 (m0:mod_t) : Lemma (state_mod_eq m0 s' s'') = update_state_mods_to1 mods s' s m0 in f1 Mod_ok; f1 Mod_cr0; f1 Mod_xer; f1 Mod_mem; f1 Mod_mem_layout; f1 Mod_stack; f1 Mod_stackTaint; let f1_reg (r:reg) : Lemma (ensures s'.regs r == s''.regs r) [SMTPat (s'.regs r)] = f1 (Mod_reg r) in let f1_vec (v:vec) : Lemma (ensures s'.vecs v == s''.vecs v) [SMTPat (s'.vecs v)] = f1 (Mod_vec v) in let f1_heaplet (n:heaplet_id) : Lemma (ensures Map16.sel (coerce s'.ms_heap).vf_heaplets n == Map16.sel (coerce s''.ms_heap).vf_heaplets n) [SMTPat (Map16.sel (coerce s'.ms_heap).vf_heaplets n)] = f1 (Mod_mem_heaplet n) in () let update_state_mods_trans (mods:mods_t) (s0 s1 s2:state) : Lemma (requires update_state_mods mods s1 s0 == s1 /\ update_state_mods mods s2 s1 == s2) (ensures update_state_mods mods s2 s0 == s2) = update_state_mods_from mods s1 s0; update_state_mods_from mods s2 s1; update_state_mods_to mods s2 s0 let rec update_state_mods_weaken1 (mods mods':mods_t) (s' s:state) (m0:mod_t) : Lemma (requires (mods_contains1 mods m0 \/ state_mod_eq m0 s s') /\ mods_contains mods' mods) (ensures (mods_contains1 mods' m0 \/ state_mod_eq m0 s s')) = match mods with | [] -> () | _::mods -> if mods_contains mods' mods && mods_contains1 mods m0 then update_state_mods_weaken1 mods mods' s' s m0 let update_state_mods_weaken (mods mods':mods_t) (s' s:state) : Lemma (requires update_state_mods mods s' s == s' /\ mods_contains mods' mods) (ensures update_state_mods mods' s' s == s') = update_state_mods_from mods s' s; let f1 (m0:mod_t) : Lemma (mods_contains1 mods' m0 \/ state_mod_eq m0 s s') = update_state_mods_weaken1 mods mods' s' s m0 in FStar.Classical.forall_intro f1; update_state_mods_to mods' s' s let call_QPURE (#a:Type0) (#cs:codes) (r:range) (msg:string) (pre:((unit -> GTot Type0) -> GTot Type0){is_monotonic pre}) (l:unit -> PURE unit (as_pure_wp pre)) (qcs:quickCodes a cs) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Lemma (requires (forall (p:unit -> GTot Type0).{:pattern pre p} (wp cs qcs mods k s0 ==> p ()) ==> label r msg (pre p))) (ensures wp cs qcs mods k s0) = l () (* let call_QBindPURE (#a #b:Type0) (#cs:codes) (r:range) (msg:string) (pre:((b -> GTot Type0) -> GTot Type0)) (l:unit -> PURE b pre) (qcs:state -> b -> GTot (quickCodes a cs)) (mods:mods_t) (k:state -> a -> Type0) (s0:state) : Ghost b (requires (forall (p:b -> GTot Type0).{:pattern pre p} (forall (g:b).{:pattern guard_free (p g)} wp cs (qcs s0 g) mods k s0 ==> p g) ==> label r msg (pre p))) (ensures fun g -> (wp cs (qcs s0 g) mods k s0)) = l () *) let rec wp_sound #a cs qcs mods k s0 = let qcs0 = qcs in match qcs with | QEmpty g -> update_state_mods_refl mods s0; let (sN, fN) = va_lemma_empty_total s0 [] in (sN, fN, g) | QSeq _ _ qc qcs -> let QProc _ _ wp1' proof = qc in let c::cs = cs in let k' = wp_Seq cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs qcs mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QBind _ _ qc qcs -> let QProc c' _ wp1' proof = qc in let c::cs = cs in let k' = wp_Bind cs qcs mods k in let (sM, fM, gM) = proof s0 k' in let (sN, fN, gN) = wp_sound cs (qcs sM gM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in update_state_mods_weaken qc.mods mods sM s0; update_state_mods_trans mods s0 sM sN; (sN, fN', gN) | QGetState f -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let (sN, fN, gN) = wp_sound cs (f sM) mods k sM in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QPURE r msg pre l qcs' -> call_QPURE r msg pre l qcs' mods k s0; wp_sound cs qcs' mods k s0 (* | QBindPURE b r msg pre l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = call_QBindPURE r msg pre l qcs' mods k s0 in let (sN, fN, gN) = wp_sound cs (qcs' s0 g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) *) | QLemma _ _ pre post l qcs' -> l (); wp_sound cs qcs' mods k s0 | QGhost b _ _ pre post l qcs' -> let c::cs = cs in let (sM, fM) = va_lemma_empty_total s0 [] in let g = l () in let (sN, fN, gN) = wp_sound cs (qcs' g) mods k s0 in let fN' = va_lemma_merge_total (c::cs) s0 fM sM fN sN in (sN, fN', gN) | QAssertBy r msg p qcsBy qcs -> empty_list_is_small cs; let _ = wp_sound [] qcsBy mods (k_AssertBy p) s0 in wp_sound cs qcs mods k s0 let qblock_proof #a #cs qcs mods s0 k = wp_sound cs (qcs s0) mods k s0 let qInlineIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = if b then ( let (sM, f0, g) = QProc?.proof qc1 s0 k in update_state_mods_weaken qc1.mods mods sM s0; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s0 k in update_state_mods_weaken qc2.mods mods sM s0; (sM, f0, g) ) let qIf_proof #a #c1 #c2 b qc1 qc2 mods s0 k = ( match b with | Cmp_eq o1 o2 -> lemma_valid_cmp_eq s0 o1 o2; lemma_cmp_eq s0 o1 o2 | Cmp_ne o1 o2 -> lemma_valid_cmp_ne s0 o1 o2; lemma_cmp_ne s0 o1 o2 | Cmp_le o1 o2 -> lemma_valid_cmp_le s0 o1 o2; lemma_cmp_le s0 o1 o2 | Cmp_ge o1 o2 -> lemma_valid_cmp_ge s0 o1 o2; lemma_cmp_ge s0 o1 o2 | Cmp_lt o1 o2 -> lemma_valid_cmp_lt s0 o1 o2; lemma_cmp_lt s0 o1 o2 | Cmp_gt o1 o2 -> lemma_valid_cmp_gt s0 o1 o2; lemma_cmp_gt s0 o1 o2 ); let s1 = {s0 with cr0 = eval_cmp_cr0 s0 (cmp_to_ocmp b)} in update_state_mods_to mods s1 s0; if eval_cmp s0 b then ( let (sM, f0, g) = QProc?.proof qc1 s1 k in va_lemma_ifElseTrue_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc1.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) ) else ( let (sM, f0, g) = QProc?.proof qc2 s1 k in va_lemma_ifElseFalse_total (cmp_to_ocmp b) c1 c2 s0 f0 sM; update_state_mods_weaken qc2.mods mods sM s1; update_state_mods_trans mods s0 s1 sM; (sM, f0, g) )
{ "checked_file": "/", "dependencies": [ "Vale.PPC64LE.Stack_Sems.fst.checked", "Vale.Lib.Map16.fsti.checked", "Vale.Arch.HeapImpl.fsti.checked", "prims.fst.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Vale.PPC64LE.QuickCodes.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": true, "full_module": "Vale.Lib.Map16", "short_module": "Map16" }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Stack_i", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.HeapImpl", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Range", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "Vale.PPC64LE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Vale.PPC64LE.QuickCodes.cmp -> qc: (_: a -> Vale.PPC64LE.QuickCode.quickCode a c) -> mods: Vale.PPC64LE.QuickCode.mods_t -> inv: (_: Vale.PPC64LE.State.state -> _: a -> Type0) -> dec: (_: Vale.PPC64LE.State.state -> _: a -> d) -> s0: Vale.PPC64LE.State.state -> s1: Vale.PPC64LE.State.state -> g1: a -> f1: Vale.PPC64LE.QuickCodes.fuel -> k: (_: Vale.PPC64LE.State.state -> _: a -> Type0) -> Prims.Ghost ((Vale.PPC64LE.State.state * Vale.PPC64LE.Decls.va_fuel) * a)
Prims.Ghost
[ "" ]
[]
[ "Vale.PPC64LE.QuickCodes.code", "Vale.PPC64LE.QuickCodes.cmp", "Vale.PPC64LE.QuickCode.quickCode", "Vale.PPC64LE.QuickCode.mods_t", "Vale.PPC64LE.State.state", "Vale.PPC64LE.QuickCodes.fuel", "Vale.PPC64LE.QuickCodes.eval_cmp", "Vale.PPC64LE.Decls.va_state", "Vale.PPC64LE.Decls.va_fuel", "Vale.PPC64LE.QuickCodes.qWhile_proof_rec", "Prims.unit", "Vale.PPC64LE.QuickCodes.update_state_mods_trans", "Vale.PPC64LE.QuickCodes.update_state_mods_weaken", "Vale.PPC64LE.QuickCode.__proj__QProc__item__mods", "Vale.PPC64LE.Decls.va_lemma_whileMerge_total", "Vale.PPC64LE.Machine_s.While", "Vale.PPC64LE.Decls.ins", "Vale.PPC64LE.Decls.ocmp", "FStar.Pervasives.Native.tuple3", "Vale.PPC64LE.Machine_s.state", "Vale.PPC64LE.QuickCode.__proj__QProc__item__proof", "FStar.Pervasives.Native.tuple2", "Vale.PPC64LE.Decls.va_lemma_whileTrue_total", "Vale.PPC64LE.QuickCode.quickProc_wp", "Vale.PPC64LE.QuickCode.__proj__QProc__item__wp", "Vale.PPC64LE.QuickCodes.wp_While_inv", "Prims.bool", "FStar.Pervasives.Native.Mktuple3", "Vale.PPC64LE.Decls.va_lemma_whileFalse_total", "Vale.PPC64LE.QuickCodes.update_state_mods_to", "Vale.PPC64LE.Machine_s.Mkstate", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ok", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__regs", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__vecs", "Vale.PPC64LE.Decls.eval_cmp_cr0", "Vale.PPC64LE.QuickCodes.cmp_to_ocmp", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__xer", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_heap", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stack", "Vale.PPC64LE.Machine_s.__proj__Mkstate__item__ms_stackTaint", "Prims.l_and", "Vale.PPC64LE.Decls.state_inv", "Vale.PPC64LE.QuickCodes.wp_While", "Vale.PPC64LE.Decls.eval_while_inv", "Prims.eq2", "Vale.PPC64LE.QuickCode.update_state_mods", "Vale.PPC64LE.Decls.eval_code" ]
[ "recursion" ]
false
false
false
false
false
let rec qWhile_proof_rec (#a #d: Type) (#c: code) (b: cmp) (qc: (a -> quickCode a c)) (mods: mods_t) (inv: (state -> a -> Type0)) (dec: (state -> a -> d)) (s0 s1: state) (g1: a) (f1: fuel) (k: (state -> a -> Type0)) : Ghost (state & va_fuel & a) (requires state_inv s1 /\ wp_While b qc mods inv dec g1 s1 k /\ eval_while_inv (While (cmp_to_ocmp b) c) s0 f1 s1 /\ update_state_mods mods s1 s0 == s1) (ensures fun (s2, f2, g2) -> eval_code (While (cmp_to_ocmp b) c) s0 f2 s2 /\ update_state_mods mods s2 s0 == s2 /\ state_inv s2 /\ k s2 g2) (decreases (dec s1 g1)) =
let ob = cmp_to_ocmp b in let s1' = { s1 with cr0 = eval_cmp_cr0 s1 (cmp_to_ocmp b) } in update_state_mods_to mods s1' s1; update_state_mods_trans mods s0 s1 s1'; if eval_cmp s1 b then (let inv2 = wp_While_inv qc mods inv dec s1 g1 in let wp = QProc?.wp (qc g1) in let s2, f2 = va_lemma_whileTrue_total ob c s0 s1 f1 in let sc, fc, gc = QProc?.proof (qc g1) s2 inv2 in let fN = va_lemma_whileMerge_total (While ob c) s0 f2 s1 fc sc in update_state_mods_weaken (qc g1).mods mods sc s2; update_state_mods_trans mods s0 s2 sc; qWhile_proof_rec b qc mods inv dec s0 sc gc fN k) else (let s2, f2 = va_lemma_whileFalse_total ob c s0 s1 f1 in (s2, f2, g1))
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.mod_short_lseq_lemma_aux
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma (requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q) (ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma (requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q) (ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
let mod_short_lseq_lemma_aux a out c = assert_norm (pow2 256 - S.q < S.q); let mask = u64 0 -. c in let out1 = map2 (BB.mask_select mask) out a in assert (v mask = (if v c = 0 then 0 else ones_v U64)); BB.lseq_mask_select_lemma out a mask; assert (out1 == (if v c = 0 then a else out)); SD.bn_eval_bound a 4; SD.bn_eval_bound out 4; lemma_check_overflow (SD.bn_v a); lemma_get_carry_from_bn_add (SD.bn_v out) (v c); assert (v c = (if SD.bn_v a < S.q then 0 else 1)); if SD.bn_v a < S.q then begin assert (SD.bn_v out1 == SD.bn_v a); Math.Lemmas.small_mod (SD.bn_v a) S.q end else begin assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256); Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1; assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q); Math.Lemmas.small_mod (SD.bn_v out1) S.q end
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 142, "start_col": 0, "start_line": 120 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2)) let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2) val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2)) let is_qelem_eq_vartime4_lemma f1 f2 = if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2 #pop-options val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128)) let is_qelem_lt_pow2_128_vartime4_lemma f = let (f0, f1, f2, f3) = f in assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192); assert (v f0 + v f1 * pow2 64 < pow2 128); if v f2 = 0 && v f3 = 0 then () else begin Math.Lemmas.pow2_lt_compat 192 128; assert (pow2 128 <= qas_nat4 f) end val lemma_check_overflow: b:nat{b < pow2 256} -> Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in overflow = (if b < S.q then 0 else 1)) let lemma_check_overflow b = let overflow = (b + (pow2 256 - S.q)) / pow2 256 in if b < S.q then begin assert (pow2 256 + b - S.q < pow2 256); assert (pow2 256 - S.q <= pow2 256 + b - S.q); assert_norm (0 < pow2 256 - S.q); Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256); assert (overflow = 0) end else begin assert (pow2 256 <= pow2 256 + b - S.q); Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256); Math.Lemmas.cancel_mul_div 1 (pow2 256); assert (1 <= overflow); assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q); assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1); Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256); assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1); assert (overflow <= 1) end val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat -> Lemma ((r + c * pow2 256) / pow2 256 = c) let lemma_get_carry_from_bn_add r c = Math.Lemmas.lemma_div_plus r c (pow2 256); Math.Lemmas.small_div r (pow2 256) val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma (requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q) (ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q)
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "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.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.K256.Scalar.qelem_lseq -> out: Hacl.Spec.K256.Scalar.qelem_lseq -> c: Hacl.Spec.Bignum.Base.carry Lib.IntTypes.U64 -> FStar.Pervasives.Lemma (requires Lib.IntTypes.v c * Prims.pow2 256 + Hacl.Spec.Bignum.Definitions.bn_v out = Hacl.Spec.Bignum.Definitions.bn_v a + Prims.pow2 256 - Spec.K256.PointOps.q) (ensures Hacl.Spec.Bignum.Definitions.bn_v (Lib.Sequence.map2 (Hacl.Spec.Bignum.Base.mask_select (Lib.IntTypes.u64 0 -. c)) out a) == Hacl.Spec.Bignum.Definitions.bn_v a % Spec.K256.PointOps.q)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.K256.Scalar.qelem_lseq", "Hacl.Spec.Bignum.Base.carry", "Lib.IntTypes.U64", "Prims.op_LessThan", "Hacl.Spec.Bignum.Definitions.bn_v", "Spec.K256.PointOps.q", "FStar.Math.Lemmas.small_mod", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.nat", "Prims.bool", "Prims.int", "Prims.op_Modulus", "FStar.Math.Lemmas.lemma_mod_sub", "Prims.op_Subtraction", "Prims.op_Addition", "Prims.pow2", "Prims.b2t", "Prims.op_Equality", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Hacl.Spec.K256.Scalar.Lemmas.lemma_get_carry_from_bn_add", "Hacl.Spec.K256.Scalar.Lemmas.lemma_check_overflow", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "Lib.Sequence.lseq", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Base.lseq_mask_select_lemma", "Lib.IntTypes.ones_v", "Prims.l_Forall", "Prims.l_imp", "Lib.Sequence.index", "Hacl.Spec.Bignum.Base.mask_select", "Lib.IntTypes.int_t", "Lib.Sequence.map2", "Lib.IntTypes.uint64", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.u64", "FStar.Pervasives.assert_norm" ]
[]
false
false
true
false
false
let mod_short_lseq_lemma_aux a out c =
assert_norm (pow2 256 - S.q < S.q); let mask = u64 0 -. c in let out1 = map2 (BB.mask_select mask) out a in assert (v mask = (if v c = 0 then 0 else ones_v U64)); BB.lseq_mask_select_lemma out a mask; assert (out1 == (if v c = 0 then a else out)); SD.bn_eval_bound a 4; SD.bn_eval_bound out 4; lemma_check_overflow (SD.bn_v a); lemma_get_carry_from_bn_add (SD.bn_v out) (v c); assert (v c = (if SD.bn_v a < S.q then 0 else 1)); if SD.bn_v a < S.q then (assert (SD.bn_v out1 == SD.bn_v a); Math.Lemmas.small_mod (SD.bn_v a) S.q) else (assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256); Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1; assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q); Math.Lemmas.small_mod (SD.bn_v out1) S.q)
false