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
Vale.AES.GCTR.fst
Vale.AES.GCTR.lemma_gctr_partial_append
val lemma_gctr_partial_append (alg:algorithm) (b1 b2:nat) (p1 c1 p2 c2:seq quad32) (key:seq nat32) (icb1 icb2:quad32) : Lemma (requires gctr_partial alg b1 p1 c1 key icb1 /\ gctr_partial alg b2 p2 c2 key icb2 /\ b1 == length p1 /\ b1 == length c1 /\ b2 == length p2 /\ b2 == length c2 /\ icb2 == inc32 icb1 b1) (ensures gctr_partial alg (b1 + b2) (p1 @| p2) (c1 @| c2) key icb1)
val lemma_gctr_partial_append (alg:algorithm) (b1 b2:nat) (p1 c1 p2 c2:seq quad32) (key:seq nat32) (icb1 icb2:quad32) : Lemma (requires gctr_partial alg b1 p1 c1 key icb1 /\ gctr_partial alg b2 p2 c2 key icb2 /\ b1 == length p1 /\ b1 == length c1 /\ b2 == length p2 /\ b2 == length c2 /\ icb2 == inc32 icb1 b1) (ensures gctr_partial alg (b1 + b2) (p1 @| p2) (c1 @| c2) key icb1)
let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 59, "start_col": 0, "start_line": 57 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 0, "no_plugins": false, "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Vale.AES.AES_common_s.algorithm -> b1: Prims.nat -> b2: Prims.nat -> p1: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c1: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p2: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c2: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> icb1: Vale.Def.Types_s.quad32 -> icb2: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires Vale.AES.GCTR.gctr_partial alg b1 p1 c1 key icb1 /\ Vale.AES.GCTR.gctr_partial alg b2 p2 c2 key icb2 /\ b1 == FStar.Seq.Base.length p1 /\ b1 == FStar.Seq.Base.length c1 /\ b2 == FStar.Seq.Base.length p2 /\ b2 == FStar.Seq.Base.length c2 /\ icb2 == Vale.AES.GCTR_s.inc32 icb1 b1) (ensures Vale.AES.GCTR.gctr_partial alg (b1 + b2) (p1 @| p2) (c1 @| c2) key icb1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "Prims.nat", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Prims.unit", "Vale.AES.GCTR.gctr_partial_reveal" ]
[]
true
false
true
false
false
let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 =
gctr_partial_reveal (); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.be_seq_quad32_to_bytes_tail_prefix
val be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0)) (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes (index s num_blocks)) 0 num_extra in x == x'))
val be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) : Lemma (requires (1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0)) (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes (index s num_blocks)) 0 num_extra in x == x'))
let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 39, "start_col": 0, "start_line": 22 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.nat -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length s /\ 16 * (FStar.Seq.Base.length s - 1) < num_bytes /\ num_bytes % 16 <> 0) (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let x = FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes (FStar.Seq.Base.index s num_blocks)) 0 num_extra in x == x'))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Words_s.nat8", "Prims.eq2", "FStar.Seq.Base.slice", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE", "Vale.Def.Words.Seq_s.seq_four_to_seq_BE", "Vale.Def.Types_s.nat32", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Vale.Arch.Types.slice_commutes_be_seq_quad32_to_bytes", "FStar.Seq.Base.create", "Vale.Arch.Types.be_quad32_to_bytes", "Vale.Def.Words_s.nat32", "Vale.Def.Words_s.four", "Vale.Arch.Types.be_seq_quad32_to_bytes_of_singleton", "FStar.Seq.Base.index", "Prims.int", "Prims.op_Division", "Prims.op_Modulus" ]
[]
true
false
true
false
false
let be_seq_quad32_to_bytes_tail_prefix (s: seq quad32) (num_bytes: nat) =
let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16) ) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.pad_to_128_bits_multiples
val pad_to_128_bits_multiples (b: seq nat8) : Lemma (let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
val pad_to_128_bits_multiples (b: seq nat8) : Lemma (let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () )
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 68, "start_col": 0, "start_line": 41 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Seq.Base.seq Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (ensures (let full_blocks = (FStar.Seq.Base.length b / 16) * 16 in let _ = FStar.Seq.Properties.split b full_blocks in (let FStar.Pervasives.Native.Mktuple2 #_ #_ full_bytes partial_bytes = _ in Vale.AES.GCTR_BE_s.pad_to_128_bits b == full_bytes @| Vale.AES.GCTR_BE_s.pad_to_128_bits partial_bytes) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat8", "Prims.op_LessThan", "FStar.Seq.Base.length", "Prims.unit", "FStar.Seq.Base.append_empty_l", "Vale.AES.GCTR_BE_s.pad_to_128_bits", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.empty", "Prims.bool", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.op_At_Bar", "FStar.Seq.Properties.lemma_split", "FStar.Seq.Base.equal", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.create", "Prims.op_Subtraction", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let pad_to_128_bits_multiples (b: seq nat8) : Lemma (let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) =
let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then (assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l (pad_to_128_bits partial_bytes); ()) else (assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then (lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); ()) else (let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); ()); ())
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_encrypt_recursive_length
val gctr_encrypt_recursive_length (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))]
val gctr_encrypt_recursive_length (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))]
let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1)
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 113, "start_col": 0, "start_line": 105 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *)
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 0, "no_plugins": false, "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
icb: Vale.Def.Types_s.quad32 -> plain: Vale.AES.GCTR_s.gctr_plain_internal_LE -> alg: Vale.AES.AES_common_s.algorithm -> key: Vale.AES.AES_s.aes_key_LE alg -> i: Prims.int -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length (Vale.AES.GCTR_s.gctr_encrypt_recursive icb plain alg key i) == FStar.Seq.Base.length plain) (decreases FStar.Seq.Base.length plain) [SMTPat (FStar.Seq.Base.length (Vale.AES.GCTR_s.gctr_encrypt_recursive icb plain alg key i))]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.AES.GCTR_s.gctr_plain_internal_LE", "Vale.AES.AES_common_s.algorithm", "Vale.AES.AES_s.aes_key_LE", "Prims.int", "Prims.op_Equality", "FStar.Seq.Base.length", "Prims.bool", "Vale.AES.GCTR.gctr_encrypt_recursive_length", "FStar.Seq.Properties.tail", "Prims.op_Addition", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.nat", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec gctr_encrypt_recursive_length (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] =
if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1)
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.lemma_counter_init
val lemma_counter_init (x:quad32) (low64 low8:nat64) : Lemma (requires low64 == lo64 x /\ low8 == iand64 low64 0xff) (ensures low8 == x.lo0 % 256)
val lemma_counter_init (x:quad32) (low64 low8:nat64) : Lemma (requires low64 == lo64 x /\ low8 == iand64 low64 0xff) (ensures low8 == x.lo0 % 256)
let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 28, "start_col": 0, "start_line": 20 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0"
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 0, "no_plugins": false, "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.quad32 -> low64: Vale.Def.Types_s.nat64 -> low8: Vale.Def.Types_s.nat64 -> FStar.Pervasives.Lemma (requires low64 == Vale.Arch.Types.lo64 x /\ low8 == Vale.Arch.Types.iand64 low64 0xff) (ensures low8 == Mkfour?.lo0 x % 256)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Types_s.nat32", "Prims.op_Addition", "FStar.Mul.op_Star", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.pow2_32", "FStar.Pervasives.assert_norm", "Vale.Def.Words_s.pow2_norm", "Vale.Arch.Types.lo64_reveal", "Vale.Def.TypesNative_s.reveal_iand", "Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1" ]
[]
true
false
true
false
false
let lemma_counter_init x low64 low8 =
Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); assert (low64 == x.lo0 + x.lo1 * pow2_32); assert (low64 % 256 == x.lo0 % 256); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_partial_extend6
val gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires length plain >= bound + 6 /\ length cipher >= bound + 6 /\ is_aes_key_LE alg key /\ bound + 6 < pow2_32 /\ gctr_partial alg bound plain cipher key icb /\ index cipher (bound + 0) == quad32_xor (index plain (bound + 0)) (aes_encrypt_BE alg key (inc32lite icb (bound + 0))) /\ index cipher (bound + 1) == quad32_xor (index plain (bound + 1)) (aes_encrypt_BE alg key (inc32lite icb (bound + 1))) /\ index cipher (bound + 2) == quad32_xor (index plain (bound + 2)) (aes_encrypt_BE alg key (inc32lite icb (bound + 2))) /\ index cipher (bound + 3) == quad32_xor (index plain (bound + 3)) (aes_encrypt_BE alg key (inc32lite icb (bound + 3))) /\ index cipher (bound + 4) == quad32_xor (index plain (bound + 4)) (aes_encrypt_BE alg key (inc32lite icb (bound + 4))) /\ index cipher (bound + 5) == quad32_xor (index plain (bound + 5)) (aes_encrypt_BE alg key (inc32lite icb (bound + 5))) ) (ensures gctr_partial alg (bound + 6) plain cipher key icb)
val gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires length plain >= bound + 6 /\ length cipher >= bound + 6 /\ is_aes_key_LE alg key /\ bound + 6 < pow2_32 /\ gctr_partial alg bound plain cipher key icb /\ index cipher (bound + 0) == quad32_xor (index plain (bound + 0)) (aes_encrypt_BE alg key (inc32lite icb (bound + 0))) /\ index cipher (bound + 1) == quad32_xor (index plain (bound + 1)) (aes_encrypt_BE alg key (inc32lite icb (bound + 1))) /\ index cipher (bound + 2) == quad32_xor (index plain (bound + 2)) (aes_encrypt_BE alg key (inc32lite icb (bound + 2))) /\ index cipher (bound + 3) == quad32_xor (index plain (bound + 3)) (aes_encrypt_BE alg key (inc32lite icb (bound + 3))) /\ index cipher (bound + 4) == quad32_xor (index plain (bound + 4)) (aes_encrypt_BE alg key (inc32lite icb (bound + 4))) /\ index cipher (bound + 5) == quad32_xor (index plain (bound + 5)) (aes_encrypt_BE alg key (inc32lite icb (bound + 5))) ) (ensures gctr_partial alg (bound + 6) plain cipher key icb)
let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 73, "start_col": 0, "start_line": 70 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 0, "no_plugins": false, "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Vale.AES.AES_common_s.algorithm -> bound: Prims.nat -> plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> icb: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length plain >= bound + 6 /\ FStar.Seq.Base.length cipher >= bound + 6 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ bound + 6 < Vale.Def.Words_s.pow2_32 /\ Vale.AES.GCTR.gctr_partial alg bound plain cipher key icb /\ FStar.Seq.Base.index cipher (bound + 0) == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain (bound + 0)) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR.inc32lite icb (bound + 0))) /\ FStar.Seq.Base.index cipher (bound + 1) == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain (bound + 1)) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR.inc32lite icb (bound + 1))) /\ FStar.Seq.Base.index cipher (bound + 2) == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain (bound + 2)) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR.inc32lite icb (bound + 2))) /\ FStar.Seq.Base.index cipher (bound + 3) == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain (bound + 3)) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR.inc32lite icb (bound + 3))) /\ FStar.Seq.Base.index cipher (bound + 4) == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain (bound + 4)) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR.inc32lite icb (bound + 4))) /\ FStar.Seq.Base.index cipher (bound + 5) == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain (bound + 5)) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR.inc32lite icb (bound + 5)))) (ensures Vale.AES.GCTR.gctr_partial alg (bound + 6) plain cipher key icb)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "Prims.nat", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Prims.unit", "Vale.AES.GCTR.gctr_partial_reveal" ]
[]
true
false
true
false
false
let gctr_partial_extend6 (alg: algorithm) (bound: nat) (plain cipher: seq quad32) (key: seq nat32) (icb: quad32) =
gctr_partial_reveal (); ()
false
Steel.ST.GhostReference.fst
Steel.ST.GhostReference.write
val write (#a:Type) (#u:_) (#v:erased a) (r:ref a) (x:erased a) : STGhostT unit u (pts_to r full_perm v) (fun _ -> pts_to r full_perm x)
val write (#a:Type) (#u:_) (#v:erased a) (r:ref a) (x:erased a) : STGhostT unit u (pts_to r full_perm v) (fun _ -> pts_to r full_perm x)
let write (#a:Type) (#u:_) (#v:erased a) (r:ref a) (x:erased a) : STGhostT unit u (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = coerce_ghost (fun _ -> R.ghost_write_pt r x)
{ "file_name": "lib/steel/Steel.ST.GhostReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 48, "end_line": 80, "start_col": 0, "start_line": 72 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.GhostReference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference [@@ erasable] let ref (a:Type u#0) : Type u#0 = R.ghost_ref a let dummy_ref a = R.dummy_ghost_ref a let pts_to (#a:_) (r:ref a) (p:perm) ([@@@smt_fallback] v:a) : vprop = R.ghost_pts_to r p v let pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (#v0 #v1:a) (r:ref a) : STGhost unit u (pts_to r p v0 `star` pts_to r q v1) (fun _ -> pts_to r p v0 `star` pts_to r q v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1)) let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r) let alloc (#a:Type) (#u:_) (x:erased a) : STGhostT (ref a) u emp (fun r -> pts_to r full_perm x) = coerce_ghost (fun _ -> R.ghost_alloc_pt x) let read (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ref a) : STGhost (erased a) u (pts_to r p v) (fun x -> pts_to r p x) (requires True) (ensures fun x -> x == v) = let y = coerce_ghost (fun _ -> R.ghost_read_pt r) in y
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.GhostReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "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
r: Steel.ST.GhostReference.ref a -> x: FStar.Ghost.erased a -> Steel.ST.Effect.Ghost.STGhostT Prims.unit
Steel.ST.Effect.Ghost.STGhostT
[]
[]
[ "Steel.Memory.inames", "FStar.Ghost.erased", "Steel.ST.GhostReference.ref", "Steel.ST.Coercions.coerce_ghost", "Prims.unit", "Steel.Reference.ghost_pts_to", "Steel.FractionalPermission.full_perm", "FStar.Ghost.reveal", "Steel.Effect.Common.vprop", "Prims.l_True", "Steel.Reference.ghost_write_pt", "Steel.ST.GhostReference.pts_to" ]
[]
false
true
false
false
false
let write (#a: Type) (#u: _) (#v: erased a) (r: ref a) (x: erased a) : STGhostT unit u (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) =
coerce_ghost (fun _ -> R.ghost_write_pt r x)
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_partial_opaque_ignores_postfix
val gctr_partial_opaque_ignores_postfix (alg:algorithm) (bound:nat32) (plain plain' cipher cipher':seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain >= bound /\ length cipher >= bound /\ length plain' >= bound /\ length cipher' >= bound /\ slice plain 0 bound == slice plain' 0 bound /\ slice cipher 0 bound == slice cipher' 0 bound) (ensures gctr_partial alg bound plain cipher key icb <==> gctr_partial alg bound plain' cipher' key icb)
val gctr_partial_opaque_ignores_postfix (alg:algorithm) (bound:nat32) (plain plain' cipher cipher':seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain >= bound /\ length cipher >= bound /\ length plain' >= bound /\ length cipher' >= bound /\ slice plain 0 bound == slice plain' 0 bound /\ slice cipher 0 bound == slice cipher' 0 bound) (ensures gctr_partial alg bound plain cipher key icb <==> gctr_partial alg bound plain' cipher' key icb)
let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 68, "start_col": 0, "start_line": 61 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 0, "no_plugins": false, "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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Vale.AES.AES_common_s.algorithm -> bound: Vale.Def.Types_s.nat32 -> plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> plain': FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> cipher': FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> icb: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ FStar.Seq.Base.length plain >= bound /\ FStar.Seq.Base.length cipher >= bound /\ FStar.Seq.Base.length plain' >= bound /\ FStar.Seq.Base.length cipher' >= bound /\ FStar.Seq.Base.slice plain 0 bound == FStar.Seq.Base.slice plain' 0 bound /\ FStar.Seq.Base.slice cipher 0 bound == FStar.Seq.Base.slice cipher' 0 bound) (ensures Vale.AES.GCTR.gctr_partial alg bound plain cipher key icb <==> Vale.AES.GCTR.gctr_partial alg bound plain' cipher' key icb)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "Vale.Def.Types_s.nat32", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.unit", "Prims._assert", "Prims.l_Forall", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "FStar.Seq.Base.length", "FStar.Seq.Base.slice", "Prims.l_imp", "Prims.op_LessThanOrEqual", "Prims.eq2", "FStar.Seq.Base.index", "Vale.AES.GCTR.gctr_partial_reveal" ]
[]
false
false
true
false
false
let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb =
gctr_partial_reveal (); assert (forall i. 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i. 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i. 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i. 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); ()
false
Steel.ST.GhostReference.fst
Steel.ST.GhostReference.share
val share (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ref a) : STGhostT unit u (pts_to r p x) (fun _ -> pts_to r (half_perm p) x `star` pts_to r (half_perm p) x)
val share (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ref a) : STGhostT unit u (pts_to r p x) (fun _ -> pts_to r (half_perm p) x `star` pts_to r (half_perm p) x)
let share (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ref a) : STGhostT unit u (pts_to r p x) (fun _ -> pts_to r (half_perm p) x `star` pts_to r (half_perm p) x) = coerce_ghost (fun _ -> R.ghost_share_pt r)
{ "file_name": "lib/steel/Steel.ST.GhostReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 46, "end_line": 95, "start_col": 0, "start_line": 86 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.GhostReference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference [@@ erasable] let ref (a:Type u#0) : Type u#0 = R.ghost_ref a let dummy_ref a = R.dummy_ghost_ref a let pts_to (#a:_) (r:ref a) (p:perm) ([@@@smt_fallback] v:a) : vprop = R.ghost_pts_to r p v let pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (#v0 #v1:a) (r:ref a) : STGhost unit u (pts_to r p v0 `star` pts_to r q v1) (fun _ -> pts_to r p v0 `star` pts_to r q v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1)) let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r) let alloc (#a:Type) (#u:_) (x:erased a) : STGhostT (ref a) u emp (fun r -> pts_to r full_perm x) = coerce_ghost (fun _ -> R.ghost_alloc_pt x) let read (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ref a) : STGhost (erased a) u (pts_to r p v) (fun x -> pts_to r p x) (requires True) (ensures fun x -> x == v) = let y = coerce_ghost (fun _ -> R.ghost_read_pt r) in y let write (#a:Type) (#u:_) (#v:erased a) (r:ref a) (x:erased a) : STGhostT unit u (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = coerce_ghost (fun _ -> R.ghost_write_pt r x) let share_gen #_ #_ #_ #v r p1 p2 = coerce_ghost (fun _ -> R.ghost_share_gen_pt #_ #_ #_ #v r p1 p2)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.GhostReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "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
r: Steel.ST.GhostReference.ref a -> Steel.ST.Effect.Ghost.STGhostT Prims.unit
Steel.ST.Effect.Ghost.STGhostT
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.ST.GhostReference.ref", "Steel.ST.Coercions.coerce_ghost", "Prims.unit", "Steel.Reference.ghost_pts_to", "FStar.Ghost.reveal", "Steel.Effect.Common.star", "Steel.FractionalPermission.half_perm", "Steel.Effect.Common.vprop", "Prims.l_True", "Steel.Reference.ghost_share_pt", "Steel.ST.GhostReference.pts_to" ]
[]
false
true
false
false
false
let share (#a: Type) (#u: _) (#p: perm) (#x: erased a) (r: ref a) : STGhostT unit u (pts_to r p x) (fun _ -> (pts_to r (half_perm p) x) `star` (pts_to r (half_perm p) x)) =
coerce_ghost (fun _ -> R.ghost_share_pt r)
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.pad_to_128_bits_be_quad32_to_bytes
val pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in length final_quads == 1 /\ (let final_quad = index final_quads 0 in pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes) == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads) @| pad_to_128_bits (slice (be_quad32_to_bytes final_quad) 0 (num_bytes % 16)))))
val pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * length s /\ 16 * (length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ length s == bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in length final_quads == 1 /\ (let final_quad = index final_quads 0 in pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes) == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads) @| pad_to_128_bits (slice (be_quad32_to_bytes final_quad) 0 (num_bytes % 16)))))
let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 86, "start_col": 0, "start_line": 70 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () )
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.int -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length s /\ 16 * (FStar.Seq.Base.length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ FStar.Seq.Base.length s == Vale.AES.GCM_helpers_BE.bytes_to_quad_size num_bytes) (ensures (let num_blocks = num_bytes / 16 in let _ = FStar.Seq.Properties.split s num_blocks in (let FStar.Pervasives.Native.Mktuple2 #_ #_ full_quads final_quads = _ in FStar.Seq.Base.length final_quads == 1 /\ (let final_quad = FStar.Seq.Base.index final_quads 0 in Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE s)) 0 num_bytes) == Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE full_quads) @| Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes final_quad) 0 (num_bytes % 16)))) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.int", "Vale.Def.Words_s.nat8", "Prims.unit", "Vale.AES.GCM_helpers_BE.be_seq_quad32_to_bytes_tail_prefix", "FStar.Seq.Properties.slice_slice", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE", "Vale.Def.Words.Seq_s.seq_four_to_seq_BE", "Vale.Def.Types_s.nat32", "Prims._assert", "Prims.eq2", "Vale.Arch.Types.slice_commutes_be_seq_quad32_to_bytes0", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "FStar.Mul.op_Star", "Prims.op_Division", "FStar.Seq.Base.length", "Vale.AES.GCM_helpers_BE.pad_to_128_bits_multiples", "FStar.Seq.Base.slice", "FStar.Seq.Base.index", "Prims.op_Modulus" ]
[]
false
false
true
false
false
let pad_to_128_bits_be_quad32_to_bytes (s: seq quad32) (num_bytes: int) =
let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads, final_quads = split s num_blocks in assert (length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; let full_blocks = ((length b) / 16) * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.pow2_24
val pow2_24 : Prims.int
let pow2_24 = 0x1000000
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 296, "start_col": 7, "start_line": 296 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let pow2_24 =
0x1000000
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_indexed
val gctr_indexed (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (cipher: seq quad32) : Lemma (requires length cipher == length plain /\ (forall i. {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i)))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0)
val gctr_indexed (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (cipher: seq quad32) : Lemma (requires length cipher == length plain /\ (forall i. {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i)))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0)
let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c)
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 185, "start_col": 0, "start_line": 176 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
icb: Vale.Def.Types_s.quad32 -> plain: Vale.AES.GCTR_s.gctr_plain_internal_LE -> alg: Vale.AES.AES_common_s.algorithm -> key: Vale.AES.AES_s.aes_key_LE alg -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length cipher == FStar.Seq.Base.length plain /\ (forall (i: Prims.int { i >= 0 /\ i < FStar.Seq.Base.length plain /\ (i >= 0) /\ (i < FStar.Seq.Base.length cipher) }). {:pattern FStar.Seq.Base.index cipher i} 0 <= i /\ i < FStar.Seq.Base.length cipher ==> FStar.Seq.Base.index cipher i == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain i) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR_s.inc32 icb i)))) (ensures cipher == Vale.AES.GCTR_s.gctr_encrypt_recursive icb plain alg key 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.AES.GCTR_s.gctr_plain_internal_LE", "Vale.AES.AES_common_s.algorithm", "Vale.AES.AES_s.aes_key_LE", "FStar.Seq.Base.seq", "Prims._assert", "FStar.Seq.Base.equal", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "Prims.unit", "Vale.AES.GCTR.gctr_indexed_helper", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "Prims.l_Forall", "Prims.int", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Prims.l_imp", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.index", "Vale.Def.Types_s.quad32_xor", "Vale.AES.GCTR.aes_encrypt_BE", "Vale.AES.GCTR_s.inc32", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let gctr_indexed (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (cipher: seq quad32) : Lemma (requires length cipher == length plain /\ (forall i. {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i)))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) =
gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert (equal cipher c)
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat24
val nat24 : Type0
let nat24 = natN pow2_24
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 297, "start_col": 0, "start_line": 297 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Words_s.natN", "Vale.AES.GCTR.pow2_24" ]
[]
false
false
false
true
true
let nat24 =
natN pow2_24
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_partial_completed
val gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial_def alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0)
val gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial_def alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0)
let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 190, "start_col": 0, "start_line": 188 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Vale.AES.AES_common_s.algorithm -> plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> icb: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ FStar.Seq.Base.length plain == FStar.Seq.Base.length cipher /\ FStar.Seq.Base.length plain < Vale.Def.Words_s.pow2_32 /\ Vale.AES.GCTR.gctr_partial_def alg (FStar.Seq.Base.length cipher) plain cipher key icb) (ensures cipher == Vale.AES.GCTR_s.gctr_encrypt_recursive icb plain alg key 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Prims.unit", "Vale.AES.GCTR.gctr_indexed" ]
[]
true
false
true
false
false
let gctr_partial_completed (alg: algorithm) (plain cipher: seq quad32) (key: seq nat32) (icb: quad32) =
gctr_indexed icb plain alg key cipher; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_encrypt_length
val gctr_encrypt_length (icb_BE: quad32) (plain: gctr_plain_LE) (alg: algorithm) (key: aes_key_LE alg) : Lemma (length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))]
val gctr_encrypt_length (icb_BE: quad32) (plain: gctr_plain_LE) (alg: algorithm) (key: aes_key_LE alg) : Lemma (length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))]
let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () )
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 148, "start_col": 0, "start_line": 116 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1)
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 40, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
icb_BE: Vale.Def.Types_s.quad32 -> plain: Vale.AES.GCTR_s.gctr_plain_LE -> alg: Vale.AES.AES_common_s.algorithm -> key: Vale.AES.AES_s.aes_key_LE alg -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length (Vale.AES.GCTR_s.gctr_encrypt_LE icb_BE plain alg key) == FStar.Seq.Base.length plain) [SMTPat (FStar.Seq.Base.length (Vale.AES.GCTR_s.gctr_encrypt_LE icb_BE plain alg key))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.AES.GCTR_s.gctr_plain_LE", "Vale.AES.AES_common_s.algorithm", "Vale.AES.AES_s.aes_key_LE", "Prims.op_Equality", "Prims.int", "Vale.AES.GCTR.gctr_encrypt_recursive_length", "FStar.Seq.Base.seq", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Prims.bool", "Vale.Def.Types_s.nat8", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "FStar.Mul.op_Star", "Prims.op_Addition", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.AES.GCTR_s.gctr_encrypt_block", "Prims.op_Division", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "Vale.Def.Types_s.le_bytes_to_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "Prims.op_Subtraction", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Prims.op_Modulus", "Vale.AES.GCTR_s.gctr_encrypt_LE_reveal", "FStar.Pervasives.reveal_opaque", "Prims.l_True", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
false
false
true
false
false
let gctr_encrypt_length (icb_BE: quad32) (plain: gctr_plain_LE) (alg: algorithm) (key: aes_key_LE alg) : Lemma (length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then (let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0) else (let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); ())
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_partial_opaque_completed
val gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0)
val gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0)
let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 202, "start_col": 0, "start_line": 192 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Vale.AES.AES_common_s.algorithm -> plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> icb: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ FStar.Seq.Base.length plain == FStar.Seq.Base.length cipher /\ FStar.Seq.Base.length plain < Vale.Def.Words_s.pow2_32 /\ Vale.AES.GCTR.gctr_partial alg (FStar.Seq.Base.length cipher) plain cipher key icb) (ensures cipher == Vale.AES.GCTR_s.gctr_encrypt_recursive icb plain alg key 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat32", "Vale.AES.GCTR.gctr_partial_completed", "Prims.unit", "Vale.AES.GCTR.gctr_partial_reveal", "Prims.l_and", "Vale.AES.AES_s.is_aes_key_LE", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "Prims.b2t", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Vale.AES.GCTR.gctr_partial", "Prims.squash", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let gctr_partial_opaque_completed (alg: algorithm) (plain cipher: seq quad32) (key: seq nat32) (icb: quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) =
gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.lemma_ishl_ixor_32
val lemma_ishl_ixor_32 (x y: nat32) (k: nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k))
val lemma_ishl_ixor_32 (x y: nat32) (k: nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k))
let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 294, "start_col": 0, "start_line": 285 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat32 -> y: Vale.Def.Types_s.nat32 -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.ishl (Vale.Def.Types_s.ixor x y) k == Vale.Def.Types_s.ixor (Vale.Def.Types_s.ishl x k) (Vale.Def.Types_s.ishl y k))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Prims.nat", "Prims.unit", "FStar.UInt.shift_left_logxor_lemma", "Vale.Def.TypesNative_s.reveal_ixor", "Vale.Def.Types_s.ishl", "Vale.Def.Words_s.pow2_32", "Vale.Def.TypesNative_s.reveal_ishl", "Vale.Def.Types_s.ixor", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_ishl_ixor_32 (x y: nat32) (k: nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) =
Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_div_n_8_lower1
val lemma_div_n_8_lower1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
val lemma_div_n_8_lower1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 178, "start_col": 0, "start_line": 171 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures (Vale.Arch.Types.lo64 q / Prims.pow2 (8 * (8 - n))) * Prims.pow2 (8 * (8 - n)) / Vale.Def.Words_s.pow2_32 == (Mkfour?.lo1 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper1", "Vale.Def.Words_s.Mkfour", "Prims.unit", "Vale.Arch.Types.lo64_reveal", "Vale.Arch.Types.hi64_reveal", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Division", "FStar.Mul.op_Star", "Vale.Arch.Types.lo64", "Prims.pow2", "Prims.op_Subtraction", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_div_n_8_lower1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) =
hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_partial_to_full_basic
val gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) : Lemma (requires is_aes_key_LE alg key /\ cipher == gctr_encrypt_recursive icb_BE plain alg key 0 /\ length plain * 16 < pow2_32 ) (ensures le_seq_quad32_to_bytes cipher == gctr_encrypt_LE icb_BE (le_seq_quad32_to_bytes plain) alg key)
val gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) : Lemma (requires is_aes_key_LE alg key /\ cipher == gctr_encrypt_recursive icb_BE plain alg key 0 /\ length plain * 16 < pow2_32 ) (ensures le_seq_quad32_to_bytes cipher == gctr_encrypt_LE icb_BE (le_seq_quad32_to_bytes plain) alg key)
let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 212, "start_col": 0, "start_line": 204 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
icb_BE: Vale.Def.Types_s.quad32 -> plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ cipher == Vale.AES.GCTR_s.gctr_encrypt_recursive icb_BE plain alg key 0 /\ FStar.Seq.Base.length plain * 16 < Vale.Def.Words_s.pow2_32) (ensures Vale.Def.Types_s.le_seq_quad32_to_bytes cipher == Vale.AES.GCTR_s.gctr_encrypt_LE icb_BE (Vale.Def.Types_s.le_seq_quad32_to_bytes plain) alg key)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.AES.AES_common_s.algorithm", "Vale.Def.Types_s.nat32", "Prims.unit", "Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes", "Vale.Def.Words_s.nat8", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Seq.Base.length", "Vale.Def.Types_s.nat8", "Vale.AES.GCTR_s.gctr_encrypt_LE_reveal" ]
[]
true
false
true
false
false
let gctr_partial_to_full_basic (icb_BE: quad32) (plain: seq quad32) (alg: algorithm) (key: seq nat32) (cipher: seq quad32) =
gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper2_helper
val lemma_div_n_8_upper2_helper (q: quad32) (n: nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
val lemma_div_n_8_upper2_helper (q: quad32) (n: nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 157, "start_col": 0, "start_line": 147 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 2) (ensures (Vale.Arch.Types.hi64 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)) == 0x100000000 * Mkfour?.hi3 q + (Mkfour?.hi2 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.logical", "Prims.eq2", "Prims.int", "FStar.Mul.op_Star", "Prims.op_Division", "Vale.Arch.Types.hi64_def", "Prims.pow2", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Arch.Types.hi64_reveal", "Prims.squash", "Vale.Arch.Types.hi64", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_div_n_8_upper2_helper (q: quad32) (n: nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) =
hi64_reveal (); let Mkfour _ _ _ _ = q in let f (n: nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_four_zero
val lemma_four_zero: unit -> Lemma (ensures four_to_nat 8 (seq_to_four_BE (create 4 0)) == 0)
val lemma_four_zero: unit -> Lemma (ensures four_to_nat 8 (seq_to_four_BE (create 4 0)) == 0)
let lemma_four_zero (_:unit) : Lemma (ensures four_to_nat 8 (seq_to_four_BE (create 4 0)) == 0) = let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 267, "start_col": 0, "start_line": 262 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) = assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1) = assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_slices_be_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8); be_bytes_to_quad32_reveal (); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE (FStar.Seq.Base.create 4 0)) == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_BE", "Vale.Def.Words.Four_s.four_to_nat_unfold", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Prims.l_True", "Prims.squash", "Prims.int", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_four_zero (_: unit) : Lemma (ensures four_to_nat 8 (seq_to_four_BE (create 4 0)) == 0) =
let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.step1
val step1 (p: seq quad32) (num_bytes: nat{num_bytes < 16 * length p}) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE)
val step1 (p: seq quad32) (num_bytes: nat{num_bytes < 16 * length p}) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE)
let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 266, "start_col": 0, "start_line": 246 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *)
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.nat{num_bytes < 16 * FStar.Seq.Base.length p} -> FStar.Pervasives.Lemma (ensures (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let _ = FStar.Seq.Properties.split (FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes p ) 0 num_bytes) (num_blocks * 16) in (let FStar.Pervasives.Native.Mktuple2 #_ #_ full_blocks _ = _ in let full_quads_LE = Vale.Def.Types_s.le_bytes_to_seq_quad32 full_blocks in let p_prefix = FStar.Seq.Base.slice p 0 num_blocks in p_prefix == full_quads_LE) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Vale.Def.Types_s.nat8", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.slice", "Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes0", "Prims.int", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "FStar.Pervasives.Native.tuple2", "Vale.Def.Words_s.nat8", "FStar.Seq.Properties.split", "Prims.op_Division", "Prims.op_Modulus", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let step1 (p: seq quad32) (num_bytes: nat{num_bytes < 16 * length p}) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) =
let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_indexed_helper
val gctr_indexed_helper (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j. {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)))))) (decreases %[length plain])
val gctr_indexed_helper (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j. {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)))))) (decreases %[length plain])
let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 174, "start_col": 0, "start_line": 151 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
icb: Vale.Def.Types_s.quad32 -> plain: Vale.AES.GCTR_s.gctr_plain_internal_LE -> alg: Vale.AES.AES_common_s.algorithm -> key: Vale.AES.AES_s.aes_key_LE alg -> i: Prims.int -> FStar.Pervasives.Lemma (ensures (let cipher = Vale.AES.GCTR_s.gctr_encrypt_recursive icb plain alg key i in FStar.Seq.Base.length cipher == FStar.Seq.Base.length plain /\ (forall (j: i: Prims.int { i >= 0 /\ i < FStar.Seq.Base.length plain /\ (i >= 0) /\ (i < FStar.Seq.Base.length cipher) }). {:pattern FStar.Seq.Base.index cipher j} 0 <= j /\ j < FStar.Seq.Base.length plain ==> FStar.Seq.Base.index cipher j == Vale.Def.Types_s.quad32_xor (FStar.Seq.Base.index plain j) (Vale.AES.GCTR.aes_encrypt_BE alg key (Vale.AES.GCTR_s.inc32 icb (i + j)))))) (decreases FStar.Seq.Base.length plain)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.AES.GCTR_s.gctr_plain_internal_LE", "Vale.AES.AES_common_s.algorithm", "Vale.AES.AES_s.aes_key_LE", "Prims.int", "Prims.op_Equality", "FStar.Seq.Base.length", "Prims.bool", "FStar.Classical.forall_intro", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.index", "Vale.Def.Types_s.quad32_xor", "Vale.AES.GCTR.aes_encrypt_BE", "Vale.AES.GCTR_s.inc32", "Prims.op_Addition", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_AmpAmp", "Prims._assert", "Prims.op_Subtraction", "Vale.AES.GCTR.gctr_indexed_helper", "Vale.AES.AES_s.aes_encrypt_LE_reveal", "FStar.Seq.Base.seq", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "FStar.Seq.Properties.tail", "Prims.nat", "Prims.l_Forall", "Prims.op_GreaterThanOrEqual" ]
[ "recursion" ]
false
false
true
false
false
let rec gctr_indexed_helper (icb: quad32) (plain: gctr_plain_internal_LE) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j. {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)))))) (decreases %[length plain]) =
if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i + 1) in let helper (j: int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j))))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then (gctr_indexed_helper icb tl alg key (i + 1); assert (index r_cipher (j - 1) == quad32_xor (index tl (j - 1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1))))) in FStar.Classical.forall_intro helper
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.lemma_slice_orig_index
val lemma_slice_orig_index (#a: Type) (s s': seq a) (m n: nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i: int). {:pattern (index s i)\/(index s' i)} m <= i /\ i < n ==> index s i == index s' i))
val lemma_slice_orig_index (#a: Type) (s s': seq a) (m n: nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i: int). {:pattern (index s i)\/(index s' i)} m <= i /\ i < n ==> index s i == index s' i))
let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 276, "start_col": 0, "start_line": 269 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq a -> s': FStar.Seq.Base.seq a -> m: Prims.nat -> n: Prims.nat -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length s == FStar.Seq.Base.length s' /\ m <= n /\ n <= FStar.Seq.Base.length s /\ FStar.Seq.Base.slice s m n == FStar.Seq.Base.slice s' m n) (ensures forall (i: Prims.int). {:pattern FStar.Seq.Base.index s i\/FStar.Seq.Base.index s' i} m <= i /\ i < n ==> FStar.Seq.Base.index s i == FStar.Seq.Base.index s' i)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Prims.nat", "FStar.Classical.forall_intro", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.index", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Seq.Base.lemma_index_slice", "Prims.op_Subtraction", "FStar.Seq.Base.length", "FStar.Seq.Base.slice", "Prims.l_Forall", "Prims.int", "Prims.l_imp" ]
[]
false
false
true
false
false
let lemma_slice_orig_index (#a: Type) (s s': seq a) (m n: nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i: int). {:pattern (index s i)\/(index s' i)} m <= i /\ i < n ==> index s i == index s' i)) =
let aux (i: nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_pad_to_32_bits
val lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
val lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 131, "start_col": 0, "start_line": 112 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> s'': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ (forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i\/FStar.Seq.Base.index s'' i} i < 4 ==> FStar.Seq.Base.index s'' i == (match i < n with | true -> FStar.Seq.Base.index s i | _ -> 0))) (ensures Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE s'') == (Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE s) / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words.Seq_s.seq4", "Vale.Def.Types_s.nat8", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.pow2", "Prims._assert", "Prims.l_imp", "Prims.op_Subtraction", "Vale.Def.Words_s.natN", "Prims.op_Multiply", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_BE", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Prims.op_LessThanOrEqual", "Vale.AES.GCM_helpers_BE.lemma_pad_to_32_bits_helper", "Prims.bool", "Prims.l_or", "Prims.l_and", "Prims.b2t", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) =
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.lemma_ishl_32
val lemma_ishl_32 (x: nat32) (k: nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32)
val lemma_ishl_32 (x: nat32) (k: nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32)
let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 283, "start_col": 0, "start_line": 278 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat32 -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.ishl x k == x * Prims.pow2 k % Vale.Def.Words_s.pow2_32)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Prims.nat", "Prims.unit", "FStar.UInt.shift_left_value_lemma", "Vale.Def.TypesNative_s.reveal_ishl", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Vale.Def.Types_s.ishl", "Vale.Def.Words_s.pow2_32", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.pow2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_ishl_32 (x: nat32) (k: nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) =
Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_64_32_hi2
val lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi')) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3)
val lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi')) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3)
let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 218, "start_col": 0, "start_line": 208 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q': Vale.Def.Types_s.quad32 -> hi: Vale.Def.Types_s.nat64 -> hi': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ hi' == (hi / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 0) (Vale.Def.Words.Two_s.nat_to_two 32 hi')) (ensures hi' == 0x100000000 * Mkfour?.hi3 q' + Mkfour?.hi2 q' /\ q' == Vale.Def.Words_s.Mkfour 0 0 (Mkfour?.hi2 q') (Mkfour?.hi3 q'))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.int", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.op_Subtraction", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Prims.squash", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.four", "Vale.Def.Words_s.Mkfour", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi')) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) =
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper1
val lemma_div_n_8_upper1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
val lemma_div_n_8_upper1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 145, "start_col": 0, "start_line": 133 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures (Vale.Arch.Types.hi64 q / Prims.pow2 (8 * (8 - n))) * Prims.pow2 (8 * (8 - n)) / Vale.Def.Words_s.pow2_32 == (Mkfour?.hi3 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.logical", "Prims.eq2", "Prims.int", "Prims.op_Division", "FStar.Mul.op_Star", "Vale.Arch.Types.hi64_def", "Prims.pow2", "Prims.op_Subtraction", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Arch.Types.hi64_reveal", "Prims.squash", "Vale.Arch.Types.hi64", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_div_n_8_upper1 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) =
hi64_reveal (); let Mkfour _ _ _ _ = q in let f (n: nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_div_n_8_lower2
val lemma_div_n_8_lower2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
val lemma_div_n_8_lower2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 187, "start_col": 0, "start_line": 180 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures (Vale.Arch.Types.lo64 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)) == 0x100000000 * Mkfour?.lo1 q + (Mkfour?.lo0 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.Def.Types_s.nat32", "Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper2", "Vale.Def.Words_s.Mkfour", "Prims.unit", "Vale.Arch.Types.lo64_reveal", "Vale.Arch.Types.hi64_reveal", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.eq2", "Prims.int", "FStar.Mul.op_Star", "Prims.op_Division", "Vale.Arch.Types.lo64", "Prims.pow2", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_div_n_8_lower2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) =
hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_64_32_hi1
val lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi')) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3)
val lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi')) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3)
let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 206, "start_col": 0, "start_line": 189 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q': Vale.Def.Types_s.quad32 -> hi: Vale.Def.Types_s.nat64 -> hi': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ hi' == (hi / Prims.pow2 (8 * (8 - n))) * Prims.pow2 (8 * (8 - n)) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 0) (Vale.Def.Words.Two_s.nat_to_two 32 hi')) (ensures hi' % Vale.Def.Words_s.pow2_32 == 0 /\ hi' / Vale.Def.Words_s.pow2_32 == Mkfour?.hi3 q' /\ q' == Vale.Def.Words_s.Mkfour 0 0 0 (Mkfour?.hi3 q'))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.int", "Prims.op_Modulus", "Prims.op_Division", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Vale.Def.Words_s.pow2_32", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Prims.squash", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Words_s.four", "Vale.Def.Words_s.Mkfour", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi')) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) =
assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_1_helper2
val nat32_xor_bytewise_1_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000) (ensures t.lo0 == t'.lo0)
val nat32_xor_bytewise_1_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000) (ensures t.lo0 == t'.lo0)
let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 344, "start_col": 0, "start_line": 329 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat32 -> x': Vale.Def.Types_s.nat32 -> t: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires x == Vale.Def.Words.Four_s.four_to_nat 8 t /\ x' == Vale.Def.Words.Four_s.four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000) (ensures Mkfour?.lo0 t == Mkfour?.lo0 t')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.AES.GCTR.nat32_xor_bytewise_1_helper1", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Prims.int", "Prims.op_Addition", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.pow2_32", "Prims.op_Modulus", "Prims.squash", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_1_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000) (ensures t.lo0 == t'.lo0) =
let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_pad_to_32_bits_helper
val lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 2 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
val lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 2 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 110, "start_col": 0, "start_line": 89 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> s'': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 2 /\ (forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i\/FStar.Seq.Base.index s'' i} i < 4 ==> FStar.Seq.Base.index s'' i == (match i < n with | true -> FStar.Seq.Base.index s i | _ -> 0))) (ensures Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE s'') == (Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE s) / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words.Seq_s.seq4", "Vale.Def.Types_s.nat8", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.pow2", "Prims._assert", "Prims.l_imp", "Prims.op_Subtraction", "Vale.Def.Words_s.natN", "Prims.op_Multiply", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_BE", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Prims.l_or", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "Prims.bool", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat) : Lemma (requires n <= 2 /\ (forall (i: nat). {:pattern (index s i)\/(index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0))) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) =
assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_64_32_lo2
val lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3)) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1)
val lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3)) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1)
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1) = assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 247, "start_col": 0, "start_line": 238 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) = assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q': Vale.Def.Types_s.quad32 -> lo: Vale.Def.Types_s.nat64 -> lo': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ lo' == (lo / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 lo') (Vale.Def.Words_s.Mktwo (Mkfour?.hi2 q') (Mkfour?.hi3 q'))) (ensures lo' == Mkfour?.lo0 q' + 0x100000000 * Mkfour?.lo1 q')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.int", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.op_Subtraction", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Prims.squash", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3)) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1) =
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.pad_to_128_bits_lower_8
val pad_to_128_bits_lower_8 (q:quad32) : Lemma (requires True) (ensures (let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 (hi64 q))) in q' == be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 8))))
val pad_to_128_bits_lower_8 (q:quad32) : Lemma (requires True) (ensures (let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 (hi64 q))) in q' == be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 8))))
let pad_to_128_bits_lower_8 (q:quad32) = small_division_lemma_1 (lo64 q) (pow2 64); pad_to_128_bits_lower q 8
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 383, "start_col": 0, "start_line": 381 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) = assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1) = assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_slices_be_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8); be_bytes_to_quad32_reveal (); () let lemma_four_zero (_:unit) : Lemma (ensures four_to_nat 8 (seq_to_four_BE (create 4 0)) == 0) = let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); () let pad_to_128_bits_upper (q:quad32) (num_bytes:int) = let n = num_bytes in let new_hi = ((hi64 q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in hi64_reveal (); let f (n:nat{1 <= n /\ n < 8}) = (hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == ((hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); assert_norm (f 5); assert_norm (f 6); assert_norm (f 7); assert (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64); let s = be_quad32_to_bytes q in let s' = slice s 0 n in let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 new_hi)) in let s'' = pad_to_128_bits s' in let q'' = be_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in if n < 4 then ( lemma_div_n_8_upper1 q n; lemma_64_32_hi1 q' (hi64 q) new_hi n; lemma_pad_to_32_bits s0_4 s0_4'' n; () ) else ( lemma_div_n_8_upper2 q (n - 4); lemma_64_32_hi2 q' (hi64 q) new_hi (n - 4); lemma_pad_to_32_bits s4_8 s4_8'' (n - 4); () ); lemma_slices_be_quad32_to_bytes q; lemma_slices_be_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 4 ==> equal s4_8'' zero_4); assert (equal s8_12'' zero_4); assert (equal s12_16'' zero_4); () #reset-options "--smtencoding.elim_box true --z3rlimit 100 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let pad_to_128_bits_lower (q:quad32) (num_bytes:int) = let n = num_bytes in let new_lo = (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64 in lo64_reveal (); hi64_reveal (); let f (n:nat{8 <= n /\ n < 16}) = (lo64_def q / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8) == ((lo64_def q / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64 in assert_norm (f 8); assert_norm (f 9); assert_norm (f 10); assert_norm (f 11); assert_norm (f 12); assert_norm (f 13); assert_norm (f 14); assert_norm (f 15); assert (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8) == (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64); let s = be_quad32_to_bytes q in let s' = slice s 0 n in let q' = two_two_to_four (Mktwo (nat_to_two 32 new_lo) (nat_to_two 32 (hi64 q))) in let s'' = pad_to_128_bits s' in let q'' = be_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 12 then ( lemma_div_n_8_lower1 q (n - 8); lemma_64_32_lo1 q' (lo64 q) new_lo (n - 8); lemma_pad_to_32_bits s8_12 s8_12'' (n - 8); () ) else ( lemma_div_n_8_lower2 q (n - 12); lemma_64_32_lo2 q' (lo64 q) new_lo (n - 12); lemma_pad_to_32_bits s12_16 s12_16'' (n - 12); () ); lemma_slices_be_quad32_to_bytes q; lemma_slices_be_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 12 ==> equal s12_16'' zero_4); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (ensures (let q' = Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 0) (Vale.Def.Words.Two_s.nat_to_two 32 (Vale.Arch.Types.hi64 q))) in q' == Vale.Def.Types_s.be_bytes_to_quad32 (Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes q) 0 8))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.AES.GCM_helpers_BE.pad_to_128_bits_lower", "Prims.unit", "FStar.Math.Lemmas.small_division_lemma_1", "Vale.Arch.Types.lo64", "Prims.pow2" ]
[]
true
false
true
false
false
let pad_to_128_bits_lower_8 (q: quad32) =
small_division_lemma_1 (lo64 q) (pow2 64); pad_to_128_bits_lower q 8
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper2
val lemma_div_n_8_upper2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
val lemma_div_n_8_upper2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)))
let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 169, "start_col": 0, "start_line": 159 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4) (ensures (Vale.Arch.Types.hi64 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)) == 0x100000000 * Mkfour?.hi3 q + (Mkfour?.hi2 q / Prims.pow2 (8 * (4 - n))) * Prims.pow2 (8 * (4 - n)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.op_LessThanOrEqual", "Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper2_helper", "Prims.bool", "Vale.Def.Types_s.nat32", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.logical", "Prims.eq2", "Prims.int", "FStar.Mul.op_Star", "Prims.op_Division", "Vale.Arch.Types.hi64_def", "Prims.pow2", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Arch.Types.hi64_reveal", "Prims.squash", "Vale.Arch.Types.hi64", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_div_n_8_upper2 (q: quad32) (n: nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) =
hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in let f (n: nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_slices_be_bytes_to_quad32
val lemma_slices_be_bytes_to_quad32 (s: seq16 nat8) : Lemma (ensures (let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16))))
val lemma_slices_be_bytes_to_quad32 (s: seq16 nat8) : Lemma (ensures (let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16))))
let lemma_slices_be_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8); be_bytes_to_quad32_reveal (); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 260, "start_col": 0, "start_line": 249 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) = assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1) = assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Vale.Def.Words.Seq_s.seq16 Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (ensures (let q = Vale.Def.Types_s.be_bytes_to_quad32 s in Mkfour?.hi3 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE (FStar.Seq.Base.slice s 0 4)) /\ Mkfour?.hi2 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE (FStar.Seq.Base.slice s 4 8)) /\ Mkfour?.lo1 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE (FStar.Seq.Base.slice s 8 12)) /\ Mkfour?.lo0 q == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_BE (FStar.Seq.Base.slice s 12 16))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words.Seq_s.seq16", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.Def.Types_s.be_bytes_to_quad32_reveal", "FStar.Pervasives.reveal_opaque", "FStar.Seq.Base.seq", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Seq.Base.length", "Vale.Def.Words_s.four", "Prims.op_Division", "Vale.Def.Words.Seq_s.seq_to_seq_four_BE", "Prims.l_True", "Prims.squash", "Prims.l_and", "Vale.Def.Words_s.natN", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Seq_s.seq_to_four_BE", "FStar.Seq.Base.slice", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.be_bytes_to_quad32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_slices_be_bytes_to_quad32 (s: seq16 nat8) : Lemma (ensures (let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)))) =
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8); be_bytes_to_quad32_reveal (); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_3_helper2
val nat32_xor_bytewise_3_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2)
val nat32_xor_bytewise_3_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2)
let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 380, "start_col": 0, "start_line": 365 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat32 -> x': Vale.Def.Types_s.nat32 -> t: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires x == Vale.Def.Words.Four_s.four_to_nat 8 t /\ x' == Vale.Def.Words.Four_s.four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000) (ensures Mkfour?.lo0 t == Mkfour?.lo0 t' /\ Mkfour?.lo1 t == Mkfour?.lo1 t' /\ Mkfour?.hi2 t == Mkfour?.hi2 t')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.AES.GCTR.nat32_xor_bytewise_3_helper1", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Prims.int", "Prims.op_Addition", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.pow2_32", "Prims.op_Modulus", "Prims.squash", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_3_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) =
let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_2_helper2
val nat32_xor_bytewise_2_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1)
val nat32_xor_bytewise_2_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1)
let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 363, "start_col": 0, "start_line": 346 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Vale.Def.Types_s.nat32 -> x': Vale.Def.Types_s.nat32 -> t: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires x == Vale.Def.Words.Four_s.four_to_nat 8 t /\ x' == Vale.Def.Words.Four_s.four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000) (ensures Mkfour?.lo0 t == Mkfour?.lo0 t' /\ Mkfour?.lo1 t == Mkfour?.lo1 t')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.AES.GCTR.nat32_xor_bytewise_2_helper1", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Prims.int", "Prims.op_Addition", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.pow2_32", "Prims.op_Modulus", "Prims.squash", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_2_helper2 (x x': nat32) (t t': four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) =
let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_2_helper3
val nat32_xor_bytewise_2_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000)
val nat32_xor_bytewise_2_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000)
let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 408, "start_col": 0, "start_line": 396 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> s: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> s': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires k == Vale.Def.Words.Four_s.four_to_nat 8 s /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 s' /\ Mkfour?.lo0 s == Mkfour?.lo0 s' /\ Mkfour?.lo1 s == Mkfour?.lo1 s') (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.squash", "Prims.int", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_2_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) =
let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_1_helper3
val nat32_xor_bytewise_1_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000)
val nat32_xor_bytewise_1_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000)
let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 394, "start_col": 0, "start_line": 382 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> s: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> s': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires k == Vale.Def.Words.Four_s.four_to_nat 8 s /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 s' /\ Mkfour?.lo0 s == Mkfour?.lo0 s') (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Prims.squash", "Prims.int", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_1_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) =
let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.lemma_64_32_lo1
val lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3)) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0)
val lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3)) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0)
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) = assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 236, "start_col": 0, "start_line": 220 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q': Vale.Def.Types_s.quad32 -> lo: Vale.Def.Types_s.nat64 -> lo': Vale.Def.Types_s.nat64 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ lo' == (lo / Prims.pow2 (8 * (8 - n))) * Prims.pow2 (8 * (8 - n)) /\ Vale.Def.Words.Four_s.four_to_two_two q' == Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 lo') (Vale.Def.Words_s.Mktwo (Mkfour?.hi2 q') (Mkfour?.hi3 q'))) (ensures lo' % Vale.Def.Words_s.pow2_32 == 0 /\ lo' / Vale.Def.Words_s.pow2_32 == Mkfour?.lo1 q' /\ Mkfour?.lo0 q' == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.nat64", "Prims.nat", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Two_s.nat_to_two_unfold", "Prims.int", "Prims.op_Modulus", "Prims.op_Division", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Vale.Def.Words_s.pow2_32", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_to_two_two", "Vale.Def.Words_s.Mktwo", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Prims.squash", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3)) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) =
assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_3_helper3
val nat32_xor_bytewise_3_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000)
val nat32_xor_bytewise_3_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000)
let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 422, "start_col": 0, "start_line": 410 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> s: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> s': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires k == Vale.Def.Words.Four_s.four_to_nat 8 s /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 s' /\ Mkfour?.lo0 s == Mkfour?.lo0 s' /\ Mkfour?.lo1 s == Mkfour?.lo1 s' /\ Mkfour?.hi2 s == Mkfour?.hi2 s') (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Prims.squash", "Prims.int", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_3_helper3 (k k': nat32) (s s': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) =
let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_2
val nat32_xor_bytewise_2 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1)
val nat32_xor_bytewise_2 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1)
let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 483, "start_col": 0, "start_line": 451 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> x: Vale.Def.Types_s.nat32 -> x': Vale.Def.Types_s.nat32 -> m: Vale.Def.Types_s.nat32 -> s: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> s': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires k == Vale.Def.Words.Four_s.four_to_nat 8 s /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 s' /\ x == Vale.Def.Words.Four_s.four_to_nat 8 t /\ x' == Vale.Def.Words.Four_s.four_to_nat 8 t' /\ Vale.Def.Types_s.ixor k m == x /\ Vale.Def.Types_s.ixor k' m == x' /\ Mkfour?.lo0 s == Mkfour?.lo0 s' /\ Mkfour?.lo1 s == Mkfour?.lo1 s') (ensures Mkfour?.lo0 t == Mkfour?.lo0 t' /\ Mkfour?.lo1 t == Mkfour?.lo1 t')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.AES.GCTR.nat32_xor_bytewise_2_helper2", "Vale.AES.GCTR.lemma_ishl_ixor_32", "Vale.AES.GCTR.lemma_ishl_32", "Vale.AES.GCTR.nat32_xor_bytewise_2_helper3", "Vale.Def.Words_s.nat8", "Prims.l_and", "Prims.eq2", "Vale.Def.Words_s.natN", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_2 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) =
let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; nat32_xor_bytewise_2_helper2 x x' t t'; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_1
val nat32_xor_bytewise_1 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0) (ensures t.lo0 == t'.lo0)
val nat32_xor_bytewise_1 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0) (ensures t.lo0 == t'.lo0)
let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 449, "start_col": 0, "start_line": 424 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> x: Vale.Def.Types_s.nat32 -> x': Vale.Def.Types_s.nat32 -> m: Vale.Def.Types_s.nat32 -> s: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> s': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires k == Vale.Def.Words.Four_s.four_to_nat 8 s /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 s' /\ x == Vale.Def.Words.Four_s.four_to_nat 8 t /\ x' == Vale.Def.Words.Four_s.four_to_nat 8 t' /\ Vale.Def.Types_s.ixor k m == x /\ Vale.Def.Types_s.ixor k' m == x' /\ Mkfour?.lo0 s == Mkfour?.lo0 s') (ensures Mkfour?.lo0 t == Mkfour?.lo0 t')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.AES.GCTR.nat32_xor_bytewise_1_helper2", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.pow2", "Vale.AES.GCTR.pow2_24", "Vale.AES.GCTR.lemma_ishl_ixor_32", "Vale.AES.GCTR.lemma_ishl_32", "Vale.AES.GCTR.nat32_xor_bytewise_1_helper3", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.natN", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_1 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0) (ensures t.lo0 == t'.lo0) =
let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_3
val nat32_xor_bytewise_3 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2)
val nat32_xor_bytewise_3 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2)
let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 509, "start_col": 0, "start_line": 485 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> x: Vale.Def.Types_s.nat32 -> x': Vale.Def.Types_s.nat32 -> m: Vale.Def.Types_s.nat32 -> s: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> s': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires k == Vale.Def.Words.Four_s.four_to_nat 8 s /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 s' /\ x == Vale.Def.Words.Four_s.four_to_nat 8 t /\ x' == Vale.Def.Words.Four_s.four_to_nat 8 t' /\ Vale.Def.Types_s.ixor k m == x /\ Vale.Def.Types_s.ixor k' m == x' /\ Mkfour?.lo0 s == Mkfour?.lo0 s' /\ Mkfour?.lo1 s == Mkfour?.lo1 s' /\ Mkfour?.hi2 s == Mkfour?.hi2 s') (ensures Mkfour?.lo0 t == Mkfour?.lo0 t' /\ Mkfour?.lo1 t == Mkfour?.lo1 t' /\ Mkfour?.hi2 t == Mkfour?.hi2 t')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "Vale.AES.GCTR.nat32_xor_bytewise_3_helper2", "Vale.AES.GCTR.lemma_ishl_ixor_32", "Vale.AES.GCTR.lemma_ishl_32", "Vale.AES.GCTR.nat32_xor_bytewise_3_helper3", "Vale.Def.Words_s.nat8", "Prims.l_and", "Prims.eq2", "Vale.Def.Words_s.natN", "Vale.Def.Words_s.pow2_32", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_3 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) =
let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.slice_pad_to_128_bits
val slice_pad_to_128_bits (s: seq nat8 {0 < length s /\ length s < 16}) : Lemma (slice (pad_to_128_bits s) 0 (length s) == s)
val slice_pad_to_128_bits (s: seq nat8 {0 < length s /\ length s < 16}) : Lemma (slice (pad_to_128_bits s) 0 (length s) == s)
let slice_pad_to_128_bits (s:seq nat8 { 0 < length s /\ length s < 16 }) : Lemma(slice (pad_to_128_bits s) 0 (length s) == s) = assert (length s % 16 == length s); assert (equal s (slice (pad_to_128_bits s) 0 (length s))); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 605, "start_col": 0, "start_line": 600 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; () let quad32_xor_bytewise (q q' r:quad32) (n:nat{ n <= 16 }) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) = let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else ( nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else ( nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else ( nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); () ) ) ); assert (equal (slice t 0 n) (slice t' 0 n)); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq Vale.Def.Types_s.nat8 {0 < FStar.Seq.Base.length s /\ FStar.Seq.Base.length s < 16} -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.slice (Vale.AES.GCTR_s.pad_to_128_bits s) 0 (FStar.Seq.Base.length s) == s)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat8", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Vale.AES.GCTR_s.pad_to_128_bits", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let slice_pad_to_128_bits (s: seq nat8 {0 < length s /\ length s < 16}) : Lemma (slice (pad_to_128_bits s) 0 (length s) == s) =
assert (length s % 16 == length s); assert (equal s (slice (pad_to_128_bits s) 0 (length s))); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.lemma_length_simplifier
val lemma_length_simplifier (s bytes t: seq quad32) (num_bytes: nat) : Lemma (requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\ (num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\ length s * 16 <= num_bytes /\ num_bytes < length s * 16 + 16 /\ length bytes == 1) (ensures slice (le_seq_quad32_to_bytes t) 0 num_bytes == slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes)
val lemma_length_simplifier (s bytes t: seq quad32) (num_bytes: nat) : Lemma (requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\ (num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\ length s * 16 <= num_bytes /\ num_bytes < length s * 16 + 16 /\ length bytes == 1) (ensures slice (le_seq_quad32_to_bytes t) 0 num_bytes == slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes)
let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma (requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\ (num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\ length s * 16 <= num_bytes /\ num_bytes < length s * 16 + 16 /\ length bytes == 1 ) (ensures slice (le_seq_quad32_to_bytes t) 0 num_bytes == slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes) = if num_bytes > (length s) * 16 then ( () ) else ( calc (==) { slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes; == { append_distributes_le_seq_quad32_to_bytes s bytes } slice (append (le_seq_quad32_to_bytes s) (le_seq_quad32_to_bytes bytes)) 0 num_bytes; == { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (le_seq_quad32_to_bytes s) (le_seq_quad32_to_bytes bytes) } le_seq_quad32_to_bytes s; == { assert (length (le_seq_quad32_to_bytes s) == num_bytes) } slice (le_seq_quad32_to_bytes s) 0 num_bytes; }; () )
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 751, "start_col": 0, "start_line": 728 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; () let quad32_xor_bytewise (q q' r:quad32) (n:nat{ n <= 16 }) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) = let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else ( nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else ( nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else ( nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); () ) ) ); assert (equal (slice t 0 n) (slice t' 0 n)); () let slice_pad_to_128_bits (s:seq nat8 { 0 < length s /\ length s < 16 }) : Lemma(slice (pad_to_128_bits s) 0 (length s) == s) = assert (length s % 16 == length s); assert (equal s (slice (pad_to_128_bits s) 0 (length s))); () let step2 (s:seq nat8 { 0 < length s /\ length s < 16 }) (q:quad32) (icb_BE:quad32) (alg:algorithm) (key:aes_key_LE alg) (i:int): Lemma(let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes) = let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in let enc_ctr = aes_encrypt_LE alg key (reverse_bytes_quad32 (inc32 icb_BE i)) in let icb_LE = reverse_bytes_quad32 (inc32 icb_BE i) in if s = q_bytes_prefix then ( // s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE s_quad alg key i)) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE (le_bytes_to_quad32 (pad_to_128_bits s)) alg key i)) 0 (length s) // q_cipher_bytes = gctr_encrypt_block icb_BE q alg key i le_quad32_to_bytes_to_quad32 (pad_to_128_bits s); slice_pad_to_128_bits s; quad32_xor_bytewise q (le_bytes_to_quad32 (pad_to_128_bits s)) (aes_encrypt_LE alg key icb_LE) (length s); //assert (equal s_cipher_bytes q_cipher_bytes); () ) else (); () #reset-options "--z3rlimit 30" open FStar.Seq.Properties let gctr_partial_to_full_advanced (icb_BE:quad32) (plain:seq quad32) (cipher:seq quad32) (alg:algorithm) (key:seq nat32) (num_bytes:nat) = gctr_encrypt_LE_reveal (); let num_blocks = num_bytes / 16 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 num_bytes in step1 plain num_bytes; let s = slice (le_seq_quad32_to_bytes plain) (num_blocks * 16) num_bytes in let final_p = index plain num_blocks in step2 s final_p icb_BE alg key num_blocks; let num_extra = num_bytes % 16 in let full_bytes_len = num_bytes - num_extra in let full_blocks, final_block = split plain_bytes full_bytes_len in assert (full_bytes_len % 16 == 0); assert (length full_blocks == full_bytes_len); let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in assert (cipher_quads_LE == slice cipher 0 num_blocks); // LHS quads let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in assert (le_seq_quad32_to_bytes cipher_quads_LE == le_seq_quad32_to_bytes (slice cipher 0 num_blocks)); // LHS bytes assert (length s == num_extra); let q_prefix = slice (le_quad32_to_bytes final_p) 0 num_extra in le_seq_quad32_to_bytes_tail_prefix plain num_bytes; assert (q_prefix == s); assert(final_cipher_bytes_LE == slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); // RHS bytes le_seq_quad32_to_bytes_tail_prefix cipher num_bytes; assert (slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_commutes_le_seq_quad32_to_bytes0 cipher num_blocks; assert (le_seq_quad32_to_bytes (slice cipher 0 num_blocks) == slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16)); assert (slice (slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) (length cipher * 16)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_append_adds (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes; assert (slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16) @| slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes == slice (le_seq_quad32_to_bytes cipher) 0 num_bytes); assert (cipher_bytes == (le_seq_quad32_to_bytes (slice cipher 0 num_blocks)) @| slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); () let gctr_encrypt_one_block (icb_BE plain:quad32) (alg:algorithm) (key:seq nat32) = gctr_encrypt_LE_reveal (); assert(inc32 icb_BE 0 == icb_BE); let encrypted_icb = aes_encrypt_BE alg key icb_BE in let p = le_quad32_to_bytes plain in let plain_quads_LE = le_bytes_to_seq_quad32 p in let p_seq = create 1 plain in assert (length p == 16); le_bytes_to_seq_quad32_to_bytes_one_quad plain; assert (p_seq == plain_quads_LE); let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (cipher_quads_LE == cons (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0) (gctr_encrypt_recursive icb_BE (tail plain_quads_LE) alg key (1))); assert (head plain_quads_LE == plain); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE)) == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE))); aes_encrypt_LE_reveal (); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_BE alg key icb_BE)); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain encrypted_icb); assert(gctr_encrypt_recursive icb_BE (tail p_seq) alg key 1 == empty); // OBSERVE //assert(gctr_encrypt_LE icb p alg key == cons (quad32_xor plain encrypted_icb) empty); let x = quad32_xor plain encrypted_icb in append_empty_r (create 1 x); // This is the missing piece ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> t: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.nat -> FStar.Pervasives.Lemma (requires t == (match num_bytes > FStar.Seq.Base.length s * 16 with | true -> FStar.Seq.Base.append s bytes | _ -> s) /\ (num_bytes <= FStar.Seq.Base.length s * 16 ==> num_bytes == FStar.Seq.Base.length s * 16) /\ FStar.Seq.Base.length s * 16 <= num_bytes /\ num_bytes < FStar.Seq.Base.length s * 16 + 16 /\ FStar.Seq.Base.length bytes == 1) (ensures FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes t) 0 num_bytes == FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.append s bytes )) 0 num_bytes)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Prims.bool", "Prims.unit", "FStar.Calc.calc_finish", "Vale.Def.Types_s.nat8", "Prims.eq2", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "FStar.Seq.Base.append", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Vale.Arch.Types.append_distributes_le_seq_quad32_to_bytes", "Prims.squash", "Vale.Lib.Seqs.lemma_slice_first_exactly_in_append", "Prims._assert", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.int", "Prims.op_LessThan", "Prims.op_Addition", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_length_simplifier (s bytes t: seq quad32) (num_bytes: nat) : Lemma (requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\ (num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\ length s * 16 <= num_bytes /\ num_bytes < length s * 16 + 16 /\ length bytes == 1) (ensures slice (le_seq_quad32_to_bytes t) 0 num_bytes == slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes) =
if num_bytes > (length s) * 16 then (()) else (calc ( == ) { slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes; ( == ) { append_distributes_le_seq_quad32_to_bytes s bytes } slice (append (le_seq_quad32_to_bytes s) (le_seq_quad32_to_bytes bytes)) 0 num_bytes; ( == ) { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (le_seq_quad32_to_bytes s) (le_seq_quad32_to_bytes bytes) } le_seq_quad32_to_bytes s; ( == ) { assert (length (le_seq_quad32_to_bytes s) == num_bytes) } slice (le_seq_quad32_to_bytes s) 0 num_bytes; }; ())
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise
val nat32_xor_bytewise (k k' m: nat32) (s s' t t': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n)) (ensures (forall (i: nat). {:pattern (index t i)\/(index t' i)} i < n ==> index t i == index t' i))
val nat32_xor_bytewise (k k' m: nat32) (s s' t t': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n)) (ensures (forall (i: nat). {:pattern (index t i)\/(index t' i)} i < n ==> index t i == index t' i))
let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 557, "start_col": 0, "start_line": 533 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> m: Vale.Def.Types_s.nat32 -> s: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> s': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> t: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> t': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 -> n: Prims.nat -> FStar.Pervasives.Lemma (requires n <= 4 /\ k == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s) /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s') /\ Vale.Def.Types_s.ixor k m == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE t) /\ Vale.Def.Types_s.ixor k' m == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE t') /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice s 0 n) (FStar.Seq.Base.slice s' 0 n)) (ensures forall (i: Prims.nat). {:pattern FStar.Seq.Base.index t i\/FStar.Seq.Base.index t' i} i < n ==> FStar.Seq.Base.index t i == FStar.Seq.Base.index t' i)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words.Seq_s.seq4", "Vale.Def.Types_s.nat8", "Prims.nat", "Prims.unit", "Vale.AES.GCTR.lemma_slice_orig_index", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.op_Equality", "Prims.int", "Vale.AES.GCTR.nat32_xor_bytewise_4", "Vale.Def.Words.Seq_s.seq_to_four_LE", "Prims.bool", "Vale.AES.GCTR.nat32_xor_bytewise_3", "Vale.AES.GCTR.nat32_xor_bytewise_2", "Vale.AES.GCTR.nat32_xor_bytewise_1", "Vale.Def.Words_s.natN", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.pow2_32", "Prims.l_imp", "Prims.b2t", "Prims.op_GreaterThan", "Prims.eq2", "FStar.Seq.Base.index", "Prims.l_and", "Prims.op_LessThanOrEqual", "Vale.Def.Words.Four_s.four_to_nat", "Prims.pow2", "FStar.Mul.op_Star", "Prims.squash", "Prims.l_Forall", "Prims.op_LessThan", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise (k k' m: nat32) (s s' t t': seq4 nat8) (n: nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n)) (ensures (forall (i: nat). {:pattern (index t i)\/(index t' i)} i < n ==> index t i == index t' i)) =
assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_bytes_helper
val gctr_bytes_helper (alg:algorithm) (key:seq nat32) (p128 p_bytes c128 c_bytes:seq quad32) (p_num_bytes:nat) (iv_BE:quad32) : Lemma (requires length p128 * 16 < pow2_32 /\ length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ is_aes_key_LE alg key /\ // Ensured by Gctr_core_opt gctr_partial_def alg (length p128) p128 c128 key iv_BE /\ (p_num_bytes > length p128 * 16 ==> index c_bytes 0 == gctr_encrypt_block (inc32 iv_BE (length p128)) (index p_bytes 0) alg key 0)) (ensures (let plain_raw_quads = append p128 p_bytes in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher_raw_quads = append c128 c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in is_gctr_plain_LE plain_bytes /\ cipher_bytes == gctr_encrypt_LE iv_BE plain_bytes alg key))
val gctr_bytes_helper (alg:algorithm) (key:seq nat32) (p128 p_bytes c128 c_bytes:seq quad32) (p_num_bytes:nat) (iv_BE:quad32) : Lemma (requires length p128 * 16 < pow2_32 /\ length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ is_aes_key_LE alg key /\ // Ensured by Gctr_core_opt gctr_partial_def alg (length p128) p128 c128 key iv_BE /\ (p_num_bytes > length p128 * 16 ==> index c_bytes 0 == gctr_encrypt_block (inc32 iv_BE (length p128)) (index p_bytes 0) alg key 0)) (ensures (let plain_raw_quads = append p128 p_bytes in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher_raw_quads = append c128 c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in is_gctr_plain_LE plain_bytes /\ cipher_bytes == gctr_encrypt_LE iv_BE plain_bytes alg key))
let gctr_bytes_helper alg key p128 p_bytes c128 c_bytes p_num_bytes iv_BE = let icb_BE_inc = inc32 iv_BE (length p128) in assert (gctr_encrypt_block icb_BE_inc (index p_bytes 0) alg key 0 == gctr_encrypt_block iv_BE (index p_bytes 0) alg key (length p128)); //assert (gctr_partial_def alg 1 p_bytes c_bytes key icb_BE_inc); gctr_partial_reveal (); if p_num_bytes = length p128 * 16 then ( gctr_partial_completed alg p128 c128 key iv_BE; gctr_partial_to_full_basic iv_BE p128 alg key c128; assert (le_seq_quad32_to_bytes c128 == gctr_encrypt_LE iv_BE (le_seq_quad32_to_bytes p128) alg key); assert (equal (slice (le_seq_quad32_to_bytes p128) 0 p_num_bytes) (le_seq_quad32_to_bytes p128)); assert (equal (slice (le_seq_quad32_to_bytes c128) 0 p_num_bytes) (le_seq_quad32_to_bytes c128)); () ) else ( aes_encrypt_LE_reveal (); lemma_gctr_partial_append alg (length p128) 1 p128 c128 p_bytes c_bytes key iv_BE icb_BE_inc; let plain = append p128 p_bytes in let cipher = append c128 c_bytes in let num_blocks = p_num_bytes / 16 in //gctr_partial_completed alg plain cipher key iv_BE; gctr_partial_completed alg p128 c128 key iv_BE; assert (equal (slice plain 0 num_blocks) p128); assert (equal (slice cipher 0 num_blocks) c128); gctr_partial_to_full_advanced iv_BE (append p128 p_bytes) (append c128 c_bytes) alg key p_num_bytes ); lemma_length_simplifier p128 p_bytes (if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128) p_num_bytes; lemma_length_simplifier c128 c_bytes (if p_num_bytes > length c128 * 16 then append c128 c_bytes else c128) p_num_bytes; ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 781, "start_col": 0, "start_line": 753 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; () let quad32_xor_bytewise (q q' r:quad32) (n:nat{ n <= 16 }) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) = let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else ( nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else ( nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else ( nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); () ) ) ); assert (equal (slice t 0 n) (slice t' 0 n)); () let slice_pad_to_128_bits (s:seq nat8 { 0 < length s /\ length s < 16 }) : Lemma(slice (pad_to_128_bits s) 0 (length s) == s) = assert (length s % 16 == length s); assert (equal s (slice (pad_to_128_bits s) 0 (length s))); () let step2 (s:seq nat8 { 0 < length s /\ length s < 16 }) (q:quad32) (icb_BE:quad32) (alg:algorithm) (key:aes_key_LE alg) (i:int): Lemma(let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes) = let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in let enc_ctr = aes_encrypt_LE alg key (reverse_bytes_quad32 (inc32 icb_BE i)) in let icb_LE = reverse_bytes_quad32 (inc32 icb_BE i) in if s = q_bytes_prefix then ( // s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE s_quad alg key i)) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE (le_bytes_to_quad32 (pad_to_128_bits s)) alg key i)) 0 (length s) // q_cipher_bytes = gctr_encrypt_block icb_BE q alg key i le_quad32_to_bytes_to_quad32 (pad_to_128_bits s); slice_pad_to_128_bits s; quad32_xor_bytewise q (le_bytes_to_quad32 (pad_to_128_bits s)) (aes_encrypt_LE alg key icb_LE) (length s); //assert (equal s_cipher_bytes q_cipher_bytes); () ) else (); () #reset-options "--z3rlimit 30" open FStar.Seq.Properties let gctr_partial_to_full_advanced (icb_BE:quad32) (plain:seq quad32) (cipher:seq quad32) (alg:algorithm) (key:seq nat32) (num_bytes:nat) = gctr_encrypt_LE_reveal (); let num_blocks = num_bytes / 16 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 num_bytes in step1 plain num_bytes; let s = slice (le_seq_quad32_to_bytes plain) (num_blocks * 16) num_bytes in let final_p = index plain num_blocks in step2 s final_p icb_BE alg key num_blocks; let num_extra = num_bytes % 16 in let full_bytes_len = num_bytes - num_extra in let full_blocks, final_block = split plain_bytes full_bytes_len in assert (full_bytes_len % 16 == 0); assert (length full_blocks == full_bytes_len); let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in assert (cipher_quads_LE == slice cipher 0 num_blocks); // LHS quads let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in assert (le_seq_quad32_to_bytes cipher_quads_LE == le_seq_quad32_to_bytes (slice cipher 0 num_blocks)); // LHS bytes assert (length s == num_extra); let q_prefix = slice (le_quad32_to_bytes final_p) 0 num_extra in le_seq_quad32_to_bytes_tail_prefix plain num_bytes; assert (q_prefix == s); assert(final_cipher_bytes_LE == slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); // RHS bytes le_seq_quad32_to_bytes_tail_prefix cipher num_bytes; assert (slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_commutes_le_seq_quad32_to_bytes0 cipher num_blocks; assert (le_seq_quad32_to_bytes (slice cipher 0 num_blocks) == slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16)); assert (slice (slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) (length cipher * 16)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_append_adds (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes; assert (slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16) @| slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes == slice (le_seq_quad32_to_bytes cipher) 0 num_bytes); assert (cipher_bytes == (le_seq_quad32_to_bytes (slice cipher 0 num_blocks)) @| slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); () let gctr_encrypt_one_block (icb_BE plain:quad32) (alg:algorithm) (key:seq nat32) = gctr_encrypt_LE_reveal (); assert(inc32 icb_BE 0 == icb_BE); let encrypted_icb = aes_encrypt_BE alg key icb_BE in let p = le_quad32_to_bytes plain in let plain_quads_LE = le_bytes_to_seq_quad32 p in let p_seq = create 1 plain in assert (length p == 16); le_bytes_to_seq_quad32_to_bytes_one_quad plain; assert (p_seq == plain_quads_LE); let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (cipher_quads_LE == cons (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0) (gctr_encrypt_recursive icb_BE (tail plain_quads_LE) alg key (1))); assert (head plain_quads_LE == plain); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE)) == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE))); aes_encrypt_LE_reveal (); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_BE alg key icb_BE)); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain encrypted_icb); assert(gctr_encrypt_recursive icb_BE (tail p_seq) alg key 1 == empty); // OBSERVE //assert(gctr_encrypt_LE icb p alg key == cons (quad32_xor plain encrypted_icb) empty); let x = quad32_xor plain encrypted_icb in append_empty_r (create 1 x); // This is the missing piece () let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma (requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\ (num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\ length s * 16 <= num_bytes /\ num_bytes < length s * 16 + 16 /\ length bytes == 1 ) (ensures slice (le_seq_quad32_to_bytes t) 0 num_bytes == slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes) = if num_bytes > (length s) * 16 then ( () ) else ( calc (==) { slice (le_seq_quad32_to_bytes (append s bytes)) 0 num_bytes; == { append_distributes_le_seq_quad32_to_bytes s bytes } slice (append (le_seq_quad32_to_bytes s) (le_seq_quad32_to_bytes bytes)) 0 num_bytes; == { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (le_seq_quad32_to_bytes s) (le_seq_quad32_to_bytes bytes) } le_seq_quad32_to_bytes s; == { assert (length (le_seq_quad32_to_bytes s) == num_bytes) } slice (le_seq_quad32_to_bytes s) 0 num_bytes; }; () )
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_num_bytes: Prims.nat -> iv_BE: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length p128 * 16 < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\ p_num_bytes < FStar.Seq.Base.length p128 * 16 + 16 /\ FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\ FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ Vale.AES.GCTR.gctr_partial_def alg (FStar.Seq.Base.length p128) p128 c128 key iv_BE /\ (p_num_bytes > FStar.Seq.Base.length p128 * 16 ==> FStar.Seq.Base.index c_bytes 0 == Vale.AES.GCTR_s.gctr_encrypt_block (Vale.AES.GCTR_s.inc32 iv_BE (FStar.Seq.Base.length p128)) (FStar.Seq.Base.index p_bytes 0) alg key 0)) (ensures (let plain_raw_quads = FStar.Seq.Base.append p128 p_bytes in let plain_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher_raw_quads = FStar.Seq.Base.append c128 c_bytes in let cipher_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in Vale.AES.GCTR_s.is_gctr_plain_LE plain_bytes /\ cipher_bytes == Vale.AES.GCTR_s.gctr_encrypt_LE iv_BE plain_bytes alg key))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.unit", "Vale.AES.GCTR.lemma_length_simplifier", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "FStar.Seq.Base.append", "Prims.bool", "Prims.op_Equality", "Prims.int", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Prims.eq2", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Vale.AES.GCTR.gctr_partial_to_full_basic", "Vale.AES.GCTR.gctr_partial_completed", "Vale.AES.GCTR.gctr_partial_to_full_advanced", "Prims.op_Division", "Vale.AES.GCTR.lemma_gctr_partial_append", "Vale.AES.AES_s.aes_encrypt_LE_reveal", "Vale.AES.GCTR.gctr_partial_reveal", "Vale.AES.GCTR_s.gctr_encrypt_block", "FStar.Seq.Base.index", "Vale.AES.GCTR_s.inc32" ]
[]
false
false
true
false
false
let gctr_bytes_helper alg key p128 p_bytes c128 c_bytes p_num_bytes iv_BE =
let icb_BE_inc = inc32 iv_BE (length p128) in assert (gctr_encrypt_block icb_BE_inc (index p_bytes 0) alg key 0 == gctr_encrypt_block iv_BE (index p_bytes 0) alg key (length p128)); gctr_partial_reveal (); if p_num_bytes = length p128 * 16 then (gctr_partial_completed alg p128 c128 key iv_BE; gctr_partial_to_full_basic iv_BE p128 alg key c128; assert (le_seq_quad32_to_bytes c128 == gctr_encrypt_LE iv_BE (le_seq_quad32_to_bytes p128) alg key); assert (equal (slice (le_seq_quad32_to_bytes p128) 0 p_num_bytes) (le_seq_quad32_to_bytes p128)); assert (equal (slice (le_seq_quad32_to_bytes c128) 0 p_num_bytes) (le_seq_quad32_to_bytes c128)); ()) else (aes_encrypt_LE_reveal (); lemma_gctr_partial_append alg (length p128) 1 p128 c128 p_bytes c_bytes key iv_BE icb_BE_inc; let plain = append p128 p_bytes in let cipher = append c128 c_bytes in let num_blocks = p_num_bytes / 16 in gctr_partial_completed alg p128 c128 key iv_BE; assert (equal (slice plain 0 num_blocks) p128); assert (equal (slice cipher 0 num_blocks) c128); gctr_partial_to_full_advanced iv_BE (append p128 p_bytes) (append c128 c_bytes) alg key p_num_bytes); lemma_length_simplifier p128 p_bytes (if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128) p_num_bytes; lemma_length_simplifier c128 c_bytes (if p_num_bytes > length c128 * 16 then append c128 c_bytes else c128) p_num_bytes; ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_encrypt_one_block
val gctr_encrypt_one_block (icb_BE plain:quad32) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key) (ensures gctr_encrypt_LE icb_BE (le_quad32_to_bytes plain) alg key == le_seq_quad32_to_bytes (create 1 (quad32_xor plain (aes_encrypt_BE alg key icb_BE))) )
val gctr_encrypt_one_block (icb_BE plain:quad32) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key) (ensures gctr_encrypt_LE icb_BE (le_quad32_to_bytes plain) alg key == le_seq_quad32_to_bytes (create 1 (quad32_xor plain (aes_encrypt_BE alg key icb_BE))) )
let gctr_encrypt_one_block (icb_BE plain:quad32) (alg:algorithm) (key:seq nat32) = gctr_encrypt_LE_reveal (); assert(inc32 icb_BE 0 == icb_BE); let encrypted_icb = aes_encrypt_BE alg key icb_BE in let p = le_quad32_to_bytes plain in let plain_quads_LE = le_bytes_to_seq_quad32 p in let p_seq = create 1 plain in assert (length p == 16); le_bytes_to_seq_quad32_to_bytes_one_quad plain; assert (p_seq == plain_quads_LE); let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (cipher_quads_LE == cons (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0) (gctr_encrypt_recursive icb_BE (tail plain_quads_LE) alg key (1))); assert (head plain_quads_LE == plain); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE)) == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE))); aes_encrypt_LE_reveal (); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_BE alg key icb_BE)); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain encrypted_icb); assert(gctr_encrypt_recursive icb_BE (tail p_seq) alg key 1 == empty); // OBSERVE //assert(gctr_encrypt_LE icb p alg key == cons (quad32_xor plain encrypted_icb) empty); let x = quad32_xor plain encrypted_icb in append_empty_r (create 1 x); // This is the missing piece ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 724, "start_col": 0, "start_line": 695 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; () let quad32_xor_bytewise (q q' r:quad32) (n:nat{ n <= 16 }) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) = let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else ( nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else ( nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else ( nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); () ) ) ); assert (equal (slice t 0 n) (slice t' 0 n)); () let slice_pad_to_128_bits (s:seq nat8 { 0 < length s /\ length s < 16 }) : Lemma(slice (pad_to_128_bits s) 0 (length s) == s) = assert (length s % 16 == length s); assert (equal s (slice (pad_to_128_bits s) 0 (length s))); () let step2 (s:seq nat8 { 0 < length s /\ length s < 16 }) (q:quad32) (icb_BE:quad32) (alg:algorithm) (key:aes_key_LE alg) (i:int): Lemma(let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes) = let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in let enc_ctr = aes_encrypt_LE alg key (reverse_bytes_quad32 (inc32 icb_BE i)) in let icb_LE = reverse_bytes_quad32 (inc32 icb_BE i) in if s = q_bytes_prefix then ( // s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE s_quad alg key i)) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE (le_bytes_to_quad32 (pad_to_128_bits s)) alg key i)) 0 (length s) // q_cipher_bytes = gctr_encrypt_block icb_BE q alg key i le_quad32_to_bytes_to_quad32 (pad_to_128_bits s); slice_pad_to_128_bits s; quad32_xor_bytewise q (le_bytes_to_quad32 (pad_to_128_bits s)) (aes_encrypt_LE alg key icb_LE) (length s); //assert (equal s_cipher_bytes q_cipher_bytes); () ) else (); () #reset-options "--z3rlimit 30" open FStar.Seq.Properties let gctr_partial_to_full_advanced (icb_BE:quad32) (plain:seq quad32) (cipher:seq quad32) (alg:algorithm) (key:seq nat32) (num_bytes:nat) = gctr_encrypt_LE_reveal (); let num_blocks = num_bytes / 16 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 num_bytes in step1 plain num_bytes; let s = slice (le_seq_quad32_to_bytes plain) (num_blocks * 16) num_bytes in let final_p = index plain num_blocks in step2 s final_p icb_BE alg key num_blocks; let num_extra = num_bytes % 16 in let full_bytes_len = num_bytes - num_extra in let full_blocks, final_block = split plain_bytes full_bytes_len in assert (full_bytes_len % 16 == 0); assert (length full_blocks == full_bytes_len); let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in assert (cipher_quads_LE == slice cipher 0 num_blocks); // LHS quads let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in assert (le_seq_quad32_to_bytes cipher_quads_LE == le_seq_quad32_to_bytes (slice cipher 0 num_blocks)); // LHS bytes assert (length s == num_extra); let q_prefix = slice (le_quad32_to_bytes final_p) 0 num_extra in le_seq_quad32_to_bytes_tail_prefix plain num_bytes; assert (q_prefix == s); assert(final_cipher_bytes_LE == slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); // RHS bytes le_seq_quad32_to_bytes_tail_prefix cipher num_bytes; assert (slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_commutes_le_seq_quad32_to_bytes0 cipher num_blocks; assert (le_seq_quad32_to_bytes (slice cipher 0 num_blocks) == slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16)); assert (slice (slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) (length cipher * 16)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_append_adds (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes; assert (slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16) @| slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes == slice (le_seq_quad32_to_bytes cipher) 0 num_bytes); assert (cipher_bytes == (le_seq_quad32_to_bytes (slice cipher 0 num_blocks)) @| slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
icb_BE: Vale.Def.Types_s.quad32 -> plain: Vale.Def.Types_s.quad32 -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key) (ensures Vale.AES.GCTR_s.gctr_encrypt_LE icb_BE (Vale.Def.Types_s.le_quad32_to_bytes plain) alg key == Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.create 1 (Vale.Def.Types_s.quad32_xor plain (Vale.AES.GCTR.aes_encrypt_BE alg key icb_BE))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat32", "Prims.unit", "FStar.Seq.Base.append_empty_r", "FStar.Seq.Base.create", "Vale.Def.Types_s.quad32_xor", "Prims._assert", "Prims.eq2", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "FStar.Seq.Properties.tail", "FStar.Seq.Base.empty", "Vale.AES.GCTR_s.gctr_encrypt_block", "FStar.Seq.Properties.head", "Vale.AES.GCTR.aes_encrypt_BE", "Vale.AES.AES_s.aes_encrypt_LE_reveal", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.AES.GCTR_s.inc32", "FStar.Seq.Base.cons", "Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes_one_quad", "Prims.int", "FStar.Seq.Base.length", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.Def.Words_s.nat8", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.AES.GCTR_s.gctr_encrypt_LE_reveal" ]
[]
true
false
true
false
false
let gctr_encrypt_one_block (icb_BE plain: quad32) (alg: algorithm) (key: seq nat32) =
gctr_encrypt_LE_reveal (); assert (inc32 icb_BE 0 == icb_BE); let encrypted_icb = aes_encrypt_BE alg key icb_BE in let p = le_quad32_to_bytes plain in let plain_quads_LE = le_bytes_to_seq_quad32 p in let p_seq = create 1 plain in assert (length p == 16); le_bytes_to_seq_quad32_to_bytes_one_quad plain; assert (p_seq == plain_quads_LE); let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (cipher_quads_LE == cons (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0) (gctr_encrypt_recursive icb_BE (tail plain_quads_LE) alg key (1))); assert (head plain_quads_LE == plain); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE)) == (let icb_LE = reverse_bytes_quad32 (inc32 icb_BE 0) in quad32_xor (head plain_quads_LE) (aes_encrypt_LE alg key icb_LE))); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_LE alg key (reverse_bytes_quad32 icb_BE))); aes_encrypt_LE_reveal (); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain (aes_encrypt_BE alg key icb_BE)); assert (gctr_encrypt_block icb_BE (head plain_quads_LE) alg key 0 == quad32_xor plain encrypted_icb); assert (gctr_encrypt_recursive icb_BE (tail p_seq) alg key 1 == empty); let x = quad32_xor plain encrypted_icb in append_empty_r (create 1 x); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.nat32_xor_bytewise_4
val nat32_xor_bytewise_4 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s') (ensures t == t')
val nat32_xor_bytewise_4 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s') (ensures t == t')
let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 530, "start_col": 0, "start_line": 512 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "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
k: Vale.Def.Types_s.nat32 -> k': Vale.Def.Types_s.nat32 -> x: Vale.Def.Types_s.nat32 -> x': Vale.Def.Types_s.nat32 -> m: Vale.Def.Types_s.nat32 -> s: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> s': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t: Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> t': Vale.Def.Words_s.four Vale.Def.Types_s.nat8 -> FStar.Pervasives.Lemma (requires k == Vale.Def.Words.Four_s.four_to_nat 8 s /\ k' == Vale.Def.Words.Four_s.four_to_nat 8 s' /\ x == Vale.Def.Words.Four_s.four_to_nat 8 t /\ x' == Vale.Def.Words.Four_s.four_to_nat 8 t' /\ Vale.Def.Types_s.ixor k m == x /\ Vale.Def.Types_s.ixor k' m == x' /\ s == s') (ensures t == t')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat8", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.natN", "Prims.pow2", "FStar.Mul.op_Star", "Vale.Def.Words.Four_s.four_to_nat", "Vale.Def.Words.Four_s.four_to_nat_unfold", "Vale.Def.Words_s.nat8", "Prims.l_and", "Vale.Def.Words_s.pow2_32", "Vale.Def.Types_s.ixor", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let nat32_xor_bytewise_4 (k k' x x' m: nat32) (s s' t t': four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s') (ensures t == t') =
let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t); ()
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.step2
val step2 (s: seq nat8 {0 < length s /\ length s < 16}) (q icb_BE: quad32) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes)
val step2 (s: seq nat8 {0 < length s /\ length s < 16}) (q icb_BE: quad32) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes)
let step2 (s:seq nat8 { 0 < length s /\ length s < 16 }) (q:quad32) (icb_BE:quad32) (alg:algorithm) (key:aes_key_LE alg) (i:int): Lemma(let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes) = let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in let enc_ctr = aes_encrypt_LE alg key (reverse_bytes_quad32 (inc32 icb_BE i)) in let icb_LE = reverse_bytes_quad32 (inc32 icb_BE i) in if s = q_bytes_prefix then ( // s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE s_quad alg key i)) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE (le_bytes_to_quad32 (pad_to_128_bits s)) alg key i)) 0 (length s) // q_cipher_bytes = gctr_encrypt_block icb_BE q alg key i le_quad32_to_bytes_to_quad32 (pad_to_128_bits s); slice_pad_to_128_bits s; quad32_xor_bytewise q (le_bytes_to_quad32 (pad_to_128_bits s)) (aes_encrypt_LE alg key icb_LE) (length s); //assert (equal s_cipher_bytes q_cipher_bytes); () ) else (); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 640, "start_col": 0, "start_line": 607 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; () let quad32_xor_bytewise (q q' r:quad32) (n:nat{ n <= 16 }) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) = let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else ( nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else ( nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else ( nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); () ) ) ); assert (equal (slice t 0 n) (slice t' 0 n)); () let slice_pad_to_128_bits (s:seq nat8 { 0 < length s /\ length s < 16 }) : Lemma(slice (pad_to_128_bits s) 0 (length s) == s) = assert (length s % 16 == length s); assert (equal s (slice (pad_to_128_bits s) 0 (length s))); ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Seq.Base.seq Vale.Def.Types_s.nat8 {0 < FStar.Seq.Base.length s /\ FStar.Seq.Base.length s < 16} -> q: Vale.Def.Types_s.quad32 -> icb_BE: Vale.Def.Types_s.quad32 -> alg: Vale.AES.AES_common_s.algorithm -> key: Vale.AES.AES_s.aes_key_LE alg -> i: Prims.int -> FStar.Pervasives.Lemma (ensures (let q_bytes = Vale.Def.Types_s.le_quad32_to_bytes q in let q_bytes_prefix = FStar.Seq.Base.slice q_bytes 0 (FStar.Seq.Base.length s) in let q_cipher = Vale.AES.GCTR_s.gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes q_cipher) 0 (FStar.Seq.Base.length s) in let s_quad = Vale.Def.Types_s.le_bytes_to_quad32 (Vale.AES.GCTR_s.pad_to_128_bits s) in let s_cipher = Vale.AES.GCTR_s.gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes s_cipher) 0 (FStar.Seq.Base.length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.nat8", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Def.Types_s.quad32", "Vale.AES.AES_common_s.algorithm", "Vale.AES.AES_s.aes_key_LE", "Prims.int", "Prims.unit", "Prims.op_Equality", "Vale.AES.GCTR.quad32_xor_bytewise", "Vale.Def.Types_s.le_bytes_to_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.AES.GCTR.slice_pad_to_128_bits", "Vale.Arch.Types.le_quad32_to_bytes_to_quad32", "Prims.bool", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.AES.GCTR_s.inc32", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.AES.GCTR_s.gctr_encrypt_block", "Prims.l_True", "Prims.squash", "Prims.l_imp", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let step2 (s: seq nat8 {0 < length s /\ length s < 16}) (q icb_BE: quad32) (alg: algorithm) (key: aes_key_LE alg) (i: int) : Lemma (let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes) =
let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in let enc_ctr = aes_encrypt_LE alg key (reverse_bytes_quad32 (inc32 icb_BE i)) in let icb_LE = reverse_bytes_quad32 (inc32 icb_BE i) in if s = q_bytes_prefix then (le_quad32_to_bytes_to_quad32 (pad_to_128_bits s); slice_pad_to_128_bits s; quad32_xor_bytewise q (le_bytes_to_quad32 (pad_to_128_bits s)) (aes_encrypt_LE alg key icb_LE) (length s); ()); ()
false
FStar.FiniteSet.Base.fst
FStar.FiniteSet.Base.union_is_differences_and_intersection
val union_is_differences_and_intersection (#a: eqtype) (s1 s2: set a) : Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1))
val union_is_differences_and_intersection (#a: eqtype) (s1 s2: set a) : Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1))
let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a) : Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) = assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)))
{ "file_name": "ulib/FStar.FiniteSet.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 103, "end_line": 330, "start_col": 0, "start_line": 328 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite sets as they're modeled in Dafny. @summary Type and functions for modeling finite sets *) module FStar.FiniteSet.Base module FLT = FStar.List.Tot open FStar.FunctionalExtensionality let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop = forall x. f x == x `FLT.mem` xs // Finite sets type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs} /// We represent the Dafny function [] on sets with `mem`: let mem (#a: eqtype) (x: a) (s: set a) : bool = s x /// We represent the Dafny function `Set#Card` with `cardinality`: /// /// function Set#Card<T>(Set T): int; let rec remove_repeats (#a: eqtype) (xs: list a) : (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) = match xs with | [] -> [] | hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl' let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) = remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s)) [@"opaque_to_smt"] let cardinality (#a: eqtype) (s: set a) : GTot nat = FLT.length (set_as_list s) let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a)) : Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) = Classical.exists_intro (fun xs -> f `has_elements` xs) xs; f /// We represent the Dafny function `Set#Empty` with `empty`: let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) [] /// We represent the Dafny function `Set#UnionOne` with `insert`: /// /// function Set#UnionOne<T>(Set T, T): Set T; let insert (#a: eqtype) (x: a) (s: set a): set a = intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s) /// We represent the Dafny function `Set#Singleton` with `singleton`: /// /// function Set#Singleton<T>(T): Set T; let singleton (#a: eqtype) (x: a) : set a = insert x emptyset /// We represent the Dafny function `Set#Union` with `union`: /// /// function Set#Union<T>(Set T, Set T): Set T; let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) = match xs with | [] -> ys | hd :: tl -> hd :: union_lists tl ys let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) = intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Intersection` with `intersection`: /// /// function Set#Intersection<T>(Set T, Set T): Set T; let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) = match xs with | [] -> [] | hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs' let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Difference` with `difference`: /// /// function Set#Difference<T>(Set T, Set T): Set T; let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) = match xs with | [] -> [] | hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs' let difference (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Subset` with `subset`: /// /// function Set#Subset<T>(Set T, Set T): bool; let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. (s1 x = true) ==> (s2 x = true) /// We represent the Dafny function `Set#Equal` with `equal`: /// /// function Set#Equal<T>(Set T, Set T): bool; let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 = feq s1 s2 /// We represent the Dafny function `Set#Disjoint` with `disjoint`: /// /// function Set#Disjoint<T>(Set T, Set T): bool; let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. not (s1 x && s2 x) /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) = Cons?.hd (set_as_list s) /// We now prove each of the facts that comprise `all_finite_set_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that /// requires a helper lemma, which we call `xxx_helper`. let empty_set_contains_no_elements_lemma () : Lemma (empty_set_contains_no_elements_fact) = () let length_zero_lemma () : Lemma (length_zero_fact) = introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s)) with ( reveal_opaque (`%cardinality) (cardinality #a); introduce cardinality s = 0 ==> s == emptyset with _. assert (feq s emptyset); introduce s == emptyset ==> cardinality s = 0 with _. assert (set_as_list s == []); introduce cardinality s <> 0 ==> _ with _. introduce exists x. mem x s with (Cons?.hd (set_as_list s)) and ()) let singleton_contains_argument_lemma () : Lemma (singleton_contains_argument_fact) = () let singleton_contains_lemma () : Lemma (singleton_contains_fact) = () let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a) : Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r)) (ensures remove_repeats xs == [r]) = match xs with | [x] -> () | hd :: tl -> assert (Cons?.hd tl = r); singleton_cardinality_helper r tl let singleton_cardinality_lemma () : Lemma (singleton_cardinality_fact) = introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1 with ( reveal_opaque (`%cardinality) (cardinality #a); singleton_cardinality_helper r (set_as_list (singleton r)) ) let insert_lemma () : Lemma (insert_fact) = () let insert_contains_argument_lemma () : Lemma (insert_contains_argument_fact) = () let insert_contains_lemma () : Lemma (insert_contains_fact) = () let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs}) : (xs': list a{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) = match xs with | hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a) : Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2)) (ensures FLT.length s1 = FLT.length s2) = match s1 with | [] -> () | hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s with introduce mem x s ==> cardinality (insert x s) = cardinality s with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s)) ) let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s)) ) let union_contains_lemma () : Lemma (union_contains_fact) = () let union_contains_element_from_first_argument_lemma () : Lemma (union_contains_element_from_first_argument_fact) = () let union_contains_element_from_second_argument_lemma () : Lemma (union_contains_element_from_second_argument_fact) = () let union_of_disjoint_lemma () : Lemma (union_of_disjoint_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with _. ( assert (feq (difference (union s1 s2) s1) s2); assert (feq (difference (union s1 s2) s2) s1) ) let intersection_contains_lemma () : Lemma (intersection_contains_fact) = () let union_idempotent_right_lemma () : Lemma (union_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2 with assert (feq (union (union s1 s2) s2) (union s1 s2)) let union_idempotent_left_lemma () : Lemma (union_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2 with assert (feq (union s1 (union s1 s2)) (union s1 s2)) let intersection_idempotent_right_lemma () : Lemma (intersection_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2 with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2)) let intersection_idempotent_left_lemma () : Lemma (intersection_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2 with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2)) let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a) : Lemma (requires list_nonrepeating xs1 /\ list_nonrepeating xs2 /\ list_nonrepeating xs3 /\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2)) /\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2)) (ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) = match xs1 with | [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3 | hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3) let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (requires disjoint s1 s2) (ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) = reveal_opaque (`%cardinality) (cardinality #a); union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2)) let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a) : Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3) (ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) = union_of_disjoint_sets_cardinality_lemma s1 s2; union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3 let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) = union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2); assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteSet.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.union s1 s2 == FStar.FiniteSet.Base.union (FStar.FiniteSet.Base.union (FStar.FiniteSet.Base.difference s1 s2) (FStar.FiniteSet.Base.intersection s1 s2)) (FStar.FiniteSet.Base.difference s2 s1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.FiniteSet.Base.set", "Prims._assert", "FStar.FunctionalExtensionality.feq", "Prims.bool", "FStar.FiniteSet.Base.union", "FStar.FiniteSet.Base.difference", "FStar.FiniteSet.Base.intersection", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let union_is_differences_and_intersection (#a: eqtype) (s1 s2: set a) : Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) =
assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) )
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.gctr_partial_to_full_advanced
val gctr_partial_to_full_advanced (icb_BE:quad32) (plain:seq quad32) (cipher:seq quad32) (alg:algorithm) (key:seq nat32) (num_bytes:nat) : Lemma (requires is_aes_key_LE alg key /\ 1 <= num_bytes /\ num_bytes < 16 * length plain /\ 16 * (length plain - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ num_bytes < pow2_32 /\ length plain == length cipher /\ ( let num_blocks = num_bytes / 16 in slice cipher 0 num_blocks == gctr_encrypt_recursive icb_BE (slice plain 0 num_blocks) alg key 0 /\ index cipher num_blocks == gctr_encrypt_block icb_BE (index plain num_blocks) alg key num_blocks) ) (ensures ( let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 num_bytes in cipher_bytes == gctr_encrypt_LE icb_BE plain_bytes alg key ))
val gctr_partial_to_full_advanced (icb_BE:quad32) (plain:seq quad32) (cipher:seq quad32) (alg:algorithm) (key:seq nat32) (num_bytes:nat) : Lemma (requires is_aes_key_LE alg key /\ 1 <= num_bytes /\ num_bytes < 16 * length plain /\ 16 * (length plain - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ num_bytes < pow2_32 /\ length plain == length cipher /\ ( let num_blocks = num_bytes / 16 in slice cipher 0 num_blocks == gctr_encrypt_recursive icb_BE (slice plain 0 num_blocks) alg key 0 /\ index cipher num_blocks == gctr_encrypt_block icb_BE (index plain num_blocks) alg key num_blocks) ) (ensures ( let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 num_bytes in cipher_bytes == gctr_encrypt_LE icb_BE plain_bytes alg key ))
let gctr_partial_to_full_advanced (icb_BE:quad32) (plain:seq quad32) (cipher:seq quad32) (alg:algorithm) (key:seq nat32) (num_bytes:nat) = gctr_encrypt_LE_reveal (); let num_blocks = num_bytes / 16 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 num_bytes in step1 plain num_bytes; let s = slice (le_seq_quad32_to_bytes plain) (num_blocks * 16) num_bytes in let final_p = index plain num_blocks in step2 s final_p icb_BE alg key num_blocks; let num_extra = num_bytes % 16 in let full_bytes_len = num_bytes - num_extra in let full_blocks, final_block = split plain_bytes full_bytes_len in assert (full_bytes_len % 16 == 0); assert (length full_blocks == full_bytes_len); let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in assert (cipher_quads_LE == slice cipher 0 num_blocks); // LHS quads let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in assert (le_seq_quad32_to_bytes cipher_quads_LE == le_seq_quad32_to_bytes (slice cipher 0 num_blocks)); // LHS bytes assert (length s == num_extra); let q_prefix = slice (le_quad32_to_bytes final_p) 0 num_extra in le_seq_quad32_to_bytes_tail_prefix plain num_bytes; assert (q_prefix == s); assert(final_cipher_bytes_LE == slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); // RHS bytes le_seq_quad32_to_bytes_tail_prefix cipher num_bytes; assert (slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_commutes_le_seq_quad32_to_bytes0 cipher num_blocks; assert (le_seq_quad32_to_bytes (slice cipher 0 num_blocks) == slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16)); assert (slice (slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) (length cipher * 16)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_append_adds (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes; assert (slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16) @| slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes == slice (le_seq_quad32_to_bytes cipher) 0 num_bytes); assert (cipher_bytes == (le_seq_quad32_to_bytes (slice cipher 0 num_blocks)) @| slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 692, "start_col": 0, "start_line": 645 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; () let quad32_xor_bytewise (q q' r:quad32) (n:nat{ n <= 16 }) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) = let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else ( nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else ( nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else ( nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); () ) ) ); assert (equal (slice t 0 n) (slice t' 0 n)); () let slice_pad_to_128_bits (s:seq nat8 { 0 < length s /\ length s < 16 }) : Lemma(slice (pad_to_128_bits s) 0 (length s) == s) = assert (length s % 16 == length s); assert (equal s (slice (pad_to_128_bits s) 0 (length s))); () let step2 (s:seq nat8 { 0 < length s /\ length s < 16 }) (q:quad32) (icb_BE:quad32) (alg:algorithm) (key:aes_key_LE alg) (i:int): Lemma(let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in s == q_bytes_prefix ==> s_cipher_bytes == q_cipher_bytes) = let q_bytes = le_quad32_to_bytes q in let q_bytes_prefix = slice q_bytes 0 (length s) in let q_cipher = gctr_encrypt_block icb_BE q alg key i in let q_cipher_bytes = slice (le_quad32_to_bytes q_cipher) 0 (length s) in let s_quad = le_bytes_to_quad32 (pad_to_128_bits s) in let s_cipher = gctr_encrypt_block icb_BE s_quad alg key i in let s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) in let enc_ctr = aes_encrypt_LE alg key (reverse_bytes_quad32 (inc32 icb_BE i)) in let icb_LE = reverse_bytes_quad32 (inc32 icb_BE i) in if s = q_bytes_prefix then ( // s_cipher_bytes = slice (le_quad32_to_bytes s_cipher) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE s_quad alg key i)) 0 (length s) // = slice (le_quad32_to_bytes (gctr_encrypt_block icb_BE (le_bytes_to_quad32 (pad_to_128_bits s)) alg key i)) 0 (length s) // q_cipher_bytes = gctr_encrypt_block icb_BE q alg key i le_quad32_to_bytes_to_quad32 (pad_to_128_bits s); slice_pad_to_128_bits s; quad32_xor_bytewise q (le_bytes_to_quad32 (pad_to_128_bits s)) (aes_encrypt_LE alg key icb_LE) (length s); //assert (equal s_cipher_bytes q_cipher_bytes); () ) else (); () #reset-options "--z3rlimit 30" open FStar.Seq.Properties
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
icb_BE: Vale.Def.Types_s.quad32 -> plain: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> cipher: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 -> num_bytes: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ 1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length plain /\ 16 * (FStar.Seq.Base.length plain - 1) < num_bytes /\ num_bytes % 16 <> 0 /\ num_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length plain == FStar.Seq.Base.length cipher /\ (let num_blocks = num_bytes / 16 in FStar.Seq.Base.slice cipher 0 num_blocks == Vale.AES.GCTR_s.gctr_encrypt_recursive icb_BE (FStar.Seq.Base.slice plain 0 num_blocks) alg key 0 /\ FStar.Seq.Base.index cipher num_blocks == Vale.AES.GCTR_s.gctr_encrypt_block icb_BE (FStar.Seq.Base.index plain num_blocks) alg key num_blocks)) (ensures (let plain_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes cipher) 0 num_bytes in cipher_bytes == Vale.AES.GCTR_s.gctr_encrypt_LE icb_BE plain_bytes alg key))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.AES.AES_common_s.algorithm", "Vale.Def.Types_s.nat32", "Prims.nat", "Vale.Def.Types_s.nat8", "Prims.unit", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.op_At_Bar", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_quad32_to_bytes", "FStar.Seq.Base.index", "FStar.Mul.op_Star", "Vale.Lib.Seqs.slice_append_adds", "FStar.Seq.Base.length", "Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes0", "Vale.AES.GCM_helpers.le_seq_quad32_to_bytes_tail_prefix", "Vale.Def.Words_s.nat8", "Prims.int", "Vale.AES.GCTR_s.gctr_encrypt_block", "Prims.op_Division", "Vale.AES.GCTR_s.gctr_encrypt_recursive", "Vale.Def.Types_s.le_bytes_to_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Prims.op_Modulus", "FStar.Pervasives.Native.tuple2", "FStar.Seq.Properties.split", "Prims.op_Subtraction", "Vale.AES.GCTR.step2", "Vale.AES.GCTR.step1", "Vale.AES.GCTR_s.gctr_encrypt_LE_reveal" ]
[]
false
false
true
false
false
let gctr_partial_to_full_advanced (icb_BE: quad32) (plain cipher: seq quad32) (alg: algorithm) (key: seq nat32) (num_bytes: nat) =
gctr_encrypt_LE_reveal (); let num_blocks = num_bytes / 16 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 num_bytes in step1 plain num_bytes; let s = slice (le_seq_quad32_to_bytes plain) (num_blocks * 16) num_bytes in let final_p = index plain num_blocks in step2 s final_p icb_BE alg key num_blocks; let num_extra = num_bytes % 16 in let full_bytes_len = num_bytes - num_extra in let full_blocks, final_block = split plain_bytes full_bytes_len in assert (full_bytes_len % 16 == 0); assert (length full_blocks == full_bytes_len); let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in assert (cipher_quads_LE == slice cipher 0 num_blocks); let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in assert (le_seq_quad32_to_bytes cipher_quads_LE == le_seq_quad32_to_bytes (slice cipher 0 num_blocks) ); assert (length s == num_extra); let q_prefix = slice (le_quad32_to_bytes final_p) 0 num_extra in le_seq_quad32_to_bytes_tail_prefix plain num_bytes; assert (q_prefix == s); assert (final_cipher_bytes_LE == slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); le_seq_quad32_to_bytes_tail_prefix cipher num_bytes; assert (slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_commutes_le_seq_quad32_to_bytes0 cipher num_blocks; assert (le_seq_quad32_to_bytes (slice cipher 0 num_blocks) == slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16)); assert (slice (slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) (length cipher * 16)) 0 num_extra == slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes); slice_append_adds (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes; assert (slice (le_seq_quad32_to_bytes cipher) 0 (num_blocks * 16) @| slice (le_seq_quad32_to_bytes cipher) (num_blocks * 16) num_bytes == slice (le_seq_quad32_to_bytes cipher) 0 num_bytes); assert (cipher_bytes == (le_seq_quad32_to_bytes (slice cipher 0 num_blocks)) @| slice (le_quad32_to_bytes (index cipher num_blocks)) 0 num_extra); ()
false
Steel.ST.GhostReference.fst
Steel.ST.GhostReference.gather
val gather (#a:Type) (#u:_) (#p0 #p1:perm) (#x0 #x1:erased a) (r:ref a) : STGhost unit u (pts_to r p0 x0 `star` pts_to r p1 x1) (fun _ -> pts_to r (sum_perm p0 p1) x0) (requires True) (ensures fun _ -> x0 == x1)
val gather (#a:Type) (#u:_) (#p0 #p1:perm) (#x0 #x1:erased a) (r:ref a) : STGhost unit u (pts_to r p0 x0 `star` pts_to r p1 x1) (fun _ -> pts_to r (sum_perm p0 p1) x0) (requires True) (ensures fun _ -> x0 == x1)
let gather (#a:Type) (#u:_) (#p0 #p1:perm) (#x0 #x1:erased a) (r:ref a) : STGhost unit u (pts_to r p0 x0 `star` pts_to r p1 x1) (fun _ -> pts_to r (sum_perm p0 p1) x0) (requires True) (ensures fun _ -> x0 == x1) = coerce_ghost (fun _ -> R.ghost_gather_pt #a #u #p0 #p1 #x0 #x1 r)
{ "file_name": "lib/steel/Steel.ST.GhostReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 69, "end_line": 107, "start_col": 0, "start_line": 97 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.GhostReference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference [@@ erasable] let ref (a:Type u#0) : Type u#0 = R.ghost_ref a let dummy_ref a = R.dummy_ghost_ref a let pts_to (#a:_) (r:ref a) (p:perm) ([@@@smt_fallback] v:a) : vprop = R.ghost_pts_to r p v let pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (#v0 #v1:a) (r:ref a) : STGhost unit u (pts_to r p v0 `star` pts_to r q v1) (fun _ -> pts_to r p v0 `star` pts_to r q v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1)) let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r) let alloc (#a:Type) (#u:_) (x:erased a) : STGhostT (ref a) u emp (fun r -> pts_to r full_perm x) = coerce_ghost (fun _ -> R.ghost_alloc_pt x) let read (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ref a) : STGhost (erased a) u (pts_to r p v) (fun x -> pts_to r p x) (requires True) (ensures fun x -> x == v) = let y = coerce_ghost (fun _ -> R.ghost_read_pt r) in y let write (#a:Type) (#u:_) (#v:erased a) (r:ref a) (x:erased a) : STGhostT unit u (pts_to r full_perm v) (fun _ -> pts_to r full_perm x) = coerce_ghost (fun _ -> R.ghost_write_pt r x) let share_gen #_ #_ #_ #v r p1 p2 = coerce_ghost (fun _ -> R.ghost_share_gen_pt #_ #_ #_ #v r p1 p2) let share (#a:Type) (#u:_) (#p:perm) (#x:erased a) (r:ref a) : STGhostT unit u (pts_to r p x) (fun _ -> pts_to r (half_perm p) x `star` pts_to r (half_perm p) x) = coerce_ghost (fun _ -> R.ghost_share_pt r)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.GhostReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "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
r: Steel.ST.GhostReference.ref a -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.ST.GhostReference.ref", "Steel.ST.Coercions.coerce_ghost", "Prims.unit", "Steel.Effect.Common.star", "Steel.Reference.ghost_pts_to", "FStar.Ghost.reveal", "Steel.FractionalPermission.sum_perm", "Steel.Effect.Common.vprop", "Prims.b2t", "Prims.eq2", "Steel.Reference.ghost_gather_pt", "Steel.ST.GhostReference.pts_to", "Prims.l_True" ]
[]
false
true
false
false
false
let gather (#a: Type) (#u: _) (#p0 #p1: perm) (#x0 #x1: erased a) (r: ref a) : STGhost unit u ((pts_to r p0 x0) `star` (pts_to r p1 x1)) (fun _ -> pts_to r (sum_perm p0 p1) x0) (requires True) (ensures fun _ -> x0 == x1) =
coerce_ghost (fun _ -> R.ghost_gather_pt #a #u #p0 #p1 #x0 #x1 r)
false
Vale.AES.GCTR.fst
Vale.AES.GCTR.quad32_xor_bytewise
val quad32_xor_bytewise (q q' r: quad32) (n: nat{n <= 16}) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n))
val quad32_xor_bytewise (q q' r: quad32) (n: nat{n <= 16}) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n))
let quad32_xor_bytewise (q q' r:quad32) (n:nat{ n <= 16 }) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) = let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else ( nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else ( nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else ( nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); () ) ) ); assert (equal (slice t 0 n) (slice t' 0 n)); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCTR.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 598, "start_col": 0, "start_line": 559 }
module Vale.AES.GCTR open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.AES.AES_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers #set-options "--z3rlimit 20 --max_fuel 1 --max_ifuel 0" let lemma_counter_init x low64 low8 = Vale.Poly1305.Bitvectors.lemma_bytes_and_mod1 low64; Vale.Def.TypesNative_s.reveal_iand 64 low64 0xff; assert (low8 == low64 % 256); lo64_reveal (); assert_norm (pow2_norm 32 == pow2_32); // OBSERVE assert (low64 == x.lo0 + x.lo1 * pow2_32); // OBSERVE assert (low64 % 256 == x.lo0 % 256); () let gctr_encrypt_block_offset (icb_BE:quad32) (plain_LE:quad32) (alg:algorithm) (key:seq nat32) (i:int) = () let gctr_encrypt_empty (icb_BE:quad32) (plain_LE cipher_LE:seq quad32) (alg:algorithm) (key:seq nat32) = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let plain = slice (le_seq_quad32_to_bytes plain_LE) 0 0 in let cipher = slice (le_seq_quad32_to_bytes cipher_LE) 0 0 in assert (plain == empty); assert (cipher == empty); assert (length plain == 0); assert (make_gctr_plain_LE plain == empty); let num_extra = (length (make_gctr_plain_LE plain)) % 16 in assert (num_extra == 0); let plain_quads_LE = le_bytes_to_seq_quad32 plain in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in assert (equal plain_quads_LE empty); // OBSERVE assert (plain_quads_LE == empty); assert (cipher_quads_LE == empty); assert (equal (le_seq_quad32_to_bytes cipher_quads_LE) empty); // OBSERVEs () let gctr_partial_opaque_init alg plain cipher key icb = gctr_partial_reveal (); () #restart-solver let lemma_gctr_partial_append alg b1 b2 p1 c1 p2 c2 key icb1 icb2 = gctr_partial_reveal (); () let gctr_partial_opaque_ignores_postfix alg bound plain plain' cipher cipher' key icb = gctr_partial_reveal (); // OBSERVE: assert (forall i . 0 <= i /\ i < bound ==> index plain i == index (slice plain 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index plain' i == index (slice plain' 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher i == index (slice cipher 0 bound) i); assert (forall i . 0 <= i /\ i < bound ==> index cipher' i == index (slice cipher' 0 bound) i); () let gctr_partial_extend6 (alg:algorithm) (bound:nat) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_partial_reveal (); () (* let rec seq_map_i_indexed' (#a:Type) (#b:Type) (f:int->a->b) (s:seq a) (i:int) : Tot (s':seq b { length s' == length s /\ (forall j . {:pattern index s' j} 0 <= j /\ j < length s ==> index s' j == f (i + j) (index s j)) }) (decreases (length s)) = if length s = 0 then empty else cons (f i (head s)) (seq_map_i_indexed f (tail s) (i + 1)) let rec test (icb_BE:quad32) (plain_LE:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (ensures (let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in gctr_encrypt_recursive icb_BE plain_LE alg key i == seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i)) (decreases (length plain_LE)) = let gctr_encrypt_block_curried (j:int) (p:quad32) = gctr_encrypt_block icb_BE p alg key j in let g = gctr_encrypt_recursive icb_BE plain_LE alg key i in let s = seq_map_i_indexed' gctr_encrypt_block_curried plain_LE i in if length plain_LE = 0 then ( assert(equal (g) (s)); () ) else ( test icb_BE (tail plain_LE) alg key (i+1); assert (gctr_encrypt_recursive icb_BE (tail plain_LE) alg key (i+1) == seq_map_i_indexed' gctr_encrypt_block_curried (tail plain_LE) (i+1)) ) *) let rec gctr_encrypt_recursive_length (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures length (gctr_encrypt_recursive icb plain alg key i) == length plain) (decreases %[length plain]) [SMTPat (length (gctr_encrypt_recursive icb plain alg key i))] = if length plain = 0 then () else gctr_encrypt_recursive_length icb (tail plain) alg key (i + 1) #reset-options "--z3rlimit 40" let gctr_encrypt_length (icb_BE:quad32) (plain:gctr_plain_LE) (alg:algorithm) (key:aes_key_LE alg) : Lemma(length (gctr_encrypt_LE icb_BE plain alg key) == length plain) [SMTPat (length (gctr_encrypt_LE icb_BE plain alg key))] = reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32; gctr_encrypt_LE_reveal (); let num_extra = (length plain) % 16 in let result = gctr_encrypt_LE icb_BE plain alg key in if num_extra = 0 then ( let plain_quads_LE = le_bytes_to_seq_quad32 plain in gctr_encrypt_recursive_length icb_BE plain_quads_LE alg key 0 ) else ( let full_bytes_len = (length plain) - num_extra in let full_blocks, final_block = split plain full_bytes_len in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let final_quad_LE = le_bytes_to_quad32 (pad_to_128_bits final_block) in let cipher_quads_LE = gctr_encrypt_recursive icb_BE full_quads_LE alg key 0 in let final_cipher_quad_LE = gctr_encrypt_block icb_BE final_quad_LE alg key (full_bytes_len / 16) in let cipher_bytes_full_LE = le_seq_quad32_to_bytes cipher_quads_LE in let final_cipher_bytes_LE = slice (le_quad32_to_bytes final_cipher_quad_LE) 0 num_extra in gctr_encrypt_recursive_length icb_BE full_quads_LE alg key 0; assert (length result == length cipher_bytes_full_LE + length final_cipher_bytes_LE); assert (length cipher_quads_LE == length full_quads_LE); assert (length cipher_bytes_full_LE == 16 * length cipher_quads_LE); assert (16 * length full_quads_LE == length full_blocks); assert (length cipher_bytes_full_LE == length full_blocks); () ) #reset-options let rec gctr_indexed_helper (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (i:int) : Lemma (requires True) (ensures (let cipher = gctr_encrypt_recursive icb plain alg key i in length cipher == length plain /\ (forall j . {:pattern index cipher j} 0 <= j /\ j < length plain ==> index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) )))) (decreases %[length plain]) = if length plain = 0 then () else let tl = tail plain in let cipher = gctr_encrypt_recursive icb plain alg key i in let r_cipher = gctr_encrypt_recursive icb tl alg key (i+1) in let helper (j:int) : Lemma ((0 <= j /\ j < length plain) ==> (index cipher j == quad32_xor (index plain j) (aes_encrypt_BE alg key (inc32 icb (i + j)) ))) = aes_encrypt_LE_reveal (); if 0 < j && j < length plain then ( gctr_indexed_helper icb tl alg key (i+1); assert(index r_cipher (j-1) == quad32_xor (index tl (j-1)) (aes_encrypt_BE alg key (inc32 icb (i + 1 + j - 1)) )) // OBSERVE ) else () in FStar.Classical.forall_intro helper let gctr_indexed (icb:quad32) (plain:gctr_plain_internal_LE) (alg:algorithm) (key:aes_key_LE alg) (cipher:seq quad32) : Lemma (requires length cipher == length plain /\ (forall i . {:pattern index cipher i} 0 <= i /\ i < length cipher ==> index cipher i == quad32_xor (index plain i) (aes_encrypt_BE alg key (inc32 icb i) ))) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_indexed_helper icb plain alg key 0; let c = gctr_encrypt_recursive icb plain alg key 0 in assert(equal cipher c) // OBSERVE: Invoke extensionality lemmas let gctr_partial_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) = gctr_indexed icb plain alg key cipher; () let gctr_partial_opaque_completed (alg:algorithm) (plain cipher:seq quad32) (key:seq nat32) (icb:quad32) : Lemma (requires is_aes_key_LE alg key /\ length plain == length cipher /\ length plain < pow2_32 /\ gctr_partial alg (length cipher) plain cipher key icb ) (ensures cipher == gctr_encrypt_recursive icb plain alg key 0) = gctr_partial_reveal (); gctr_partial_completed alg plain cipher key icb let gctr_partial_to_full_basic (icb_BE:quad32) (plain:seq quad32) (alg:algorithm) (key:seq nat32) (cipher:seq quad32) = gctr_encrypt_LE_reveal (); let p = le_seq_quad32_to_bytes plain in assert (length p % 16 == 0); let plain_quads_LE = le_bytes_to_seq_quad32 p in let cipher_quads_LE = gctr_encrypt_recursive icb_BE plain_quads_LE alg key 0 in let cipher_bytes = le_seq_quad32_to_bytes cipher_quads_LE in le_bytes_to_seq_quad32_to_bytes plain; () (* Want to show that: slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, out_b))) 0 num_bytes == gctr_encrypt_LE icb_BE (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) ... We know that slice (buffer128_as_seq(mem, out_b) 0 num_blocks == gctr_encrypt_recursive icb_BE (slice buffer128_as_seq(mem, in_b) 0 num_blocks) ... And we know that: get_mem out_b num_blocks == gctr_encrypt_block(icb_BE, (get_mem inb num_blocks), alg, key, num_blocks); Internally gctr_encrypt_LE will compute: full_blocks, final_block = split (slice (le_seq_quad32_to_bytes (buffer128_as_seq(mem, in_b))) 0 num_bytes) (num_blocks * 16) We'd like to show that Step1: le_bytes_to_seq_quad32 full_blocks == slice buffer128_as_seq(mem, in_b) 0 num_blocks and Step2: final_block == slice (le_quad32_to_bytes (get_mem inb num_blocks)) 0 num_extra Then we need to break down the byte-level effects of gctr_encrypt_block to show that even though the padded version of final_block differs from (get_mem inb num_blocks), after we slice it at the end, we end up with the same value *) let step1 (p:seq quad32) (num_bytes:nat{ num_bytes < 16 * length p }) : Lemma (let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in p_prefix == full_quads_LE) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_blocks, final_block = split (slice (le_seq_quad32_to_bytes p) 0 num_bytes) (num_blocks * 16) in let full_quads_LE = le_bytes_to_seq_quad32 full_blocks in let p_prefix = slice p 0 num_blocks in assert (length full_blocks == num_blocks * 16); assert (full_blocks == slice (slice (le_seq_quad32_to_bytes p) 0 num_bytes) 0 (num_blocks * 16)); assert (full_blocks == slice (le_seq_quad32_to_bytes p) 0 (num_blocks * 16)); slice_commutes_le_seq_quad32_to_bytes0 p num_blocks; assert (full_blocks == le_seq_quad32_to_bytes (slice p 0 num_blocks)); le_bytes_to_seq_quad32_to_bytes (slice p 0 num_blocks); assert (full_quads_LE == (slice p 0 num_blocks)); () #reset-options "--smtencoding.elim_box true --z3rlimit 30" let lemma_slice_orig_index (#a:Type) (s s':seq a) (m n:nat) : Lemma (requires length s == length s' /\ m <= n /\ n <= length s /\ slice s m n == slice s' m n) (ensures (forall (i:int).{:pattern (index s i) \/ (index s' i)} m <= i /\ i < n ==> index s i == index s' i)) = let aux (i:nat{m <= i /\ i < n}) : Lemma (index s i == index s' i) = lemma_index_slice s m n (i - m); lemma_index_slice s' m n (i - m) in Classical.forall_intro aux let lemma_ishl_32 (x:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 x k == x * pow2 k % pow2_32) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; FStar.UInt.shift_left_value_lemma #32 x k; () let lemma_ishl_ixor_32 (x y:nat32) (k:nat) : Lemma (ensures ishl #pow2_32 (ixor x y) k == ixor (ishl x k) (ishl y k)) = Vale.Def.TypesNative_s.reveal_ishl 32 x k; Vale.Def.TypesNative_s.reveal_ishl 32 y k; Vale.Def.TypesNative_s.reveal_ishl 32 (ixor x y) k; Vale.Def.TypesNative_s.reveal_ixor 32 x y; Vale.Def.TypesNative_s.reveal_ixor 32 (ishl x k) (ishl y k); FStar.UInt.shift_left_logxor_lemma #32 x y k; () unfold let pow2_24 = 0x1000000 let nat24 = natN pow2_24 let nat32_xor_bytewise_1_helper1 (x0 x0':nat8) (x1 x1':nat24) (x x':nat32) : Lemma (requires x == x0 + 0x100 * x1 /\ x' == x0' + 0x100 * x1' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_2_helper1 (x0 x0' x1 x1':nat16) (x x':nat32) : Lemma (requires x == x0 + 0x10000 * x1 /\ x' == x0' + 0x10000 * x1' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_3_helper1 (x0 x0':nat24) (x1 x1':nat8) (x x':nat32) : Lemma (requires x == x0 + 0x1000000 * x1 /\ x' == x0' + 0x1000000 * x1' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures x0 == x0') = () let nat32_xor_bytewise_1_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x1000000 % 0x100000000 == x' * 0x1000000 % 0x100000000 ) (ensures t.lo0 == t'.lo0) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t123 = t1 + 0x100 * t2 + 0x10000 * t3 in let t123' = t1' + 0x100 * t2' + 0x10000 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_1_helper1 t0 t0' t123 t123' x x'; () let nat32_xor_bytewise_2_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x10000 % 0x100000000 == x' * 0x10000 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t01 = t0 + 0x100 * t1 in let t23 = t2 + 0x100 * t3 in let t01' = t0' + 0x100 * t1' in let t23' = t2' + 0x100 * t3' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_2_helper1 t01 t01' t23 t23' x x'; () let nat32_xor_bytewise_3_helper2 (x x':nat32) (t t':four nat8) : Lemma (requires x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ x * 0x100 % 0x100000000 == x' * 0x100 % 0x100000000 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in let t012 = t0 + 0x100 * t1 + 0x10000 * t2 in let t012' = t0' + 0x100 * t1' + 0x10000 * t2' in assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); nat32_xor_bytewise_3_helper1 t012 t012' t3 t3' x x'; () let nat32_xor_bytewise_1_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 ) (ensures k * 0x1000000 % 0x100000000 == k' * 0x1000000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_2_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures k * 0x10000 % 0x100000000 == k' * 0x10000 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_3_helper3 (k k':nat32) (s s':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures k * 0x100 % 0x100000000 == k' * 0x100 % 0x100000000) = let Mkfour _ _ _ _ = s in let Mkfour _ _ _ _ = s' in assert_norm (four_to_nat 8 s == four_to_nat_unfold 8 s ); assert_norm (four_to_nat 8 s' == four_to_nat_unfold 8 s'); () let nat32_xor_bytewise_1 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 ) (ensures t.lo0 == t'.lo0) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_1_helper3 k k' s s'; lemma_ishl_32 k 24; lemma_ishl_32 k' 24; lemma_ishl_32 x 24; lemma_ishl_32 x' 24; lemma_ishl_ixor_32 k m 24; lemma_ishl_ixor_32 k' m 24; assert_norm (pow2 24 == pow2_24); nat32_xor_bytewise_1_helper2 x x' t t'; () let nat32_xor_bytewise_2 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_2_helper3 k k' s s'; lemma_ishl_32 k 16; lemma_ishl_32 k' 16; lemma_ishl_32 x 16; lemma_ishl_32 x' 16; lemma_ishl_ixor_32 k m 16; lemma_ishl_ixor_32 k' m 16; // assert (ishl #pow2_32 k 16 == k * 0x10000 % 0x100000000); // assert (ishl #pow2_32 k' 16 == k' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == x * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x' 16 == x' * 0x10000 % 0x100000000); // assert (ishl #pow2_32 x 16 == ixor (ishl k 16) (ishl m 16)); // assert (ishl #pow2_32 x' 16 == ixor (ishl k' 16) (ishl m 16)); // assert (x * 0x10000 % 0x100000000 == ixor (k * 0x10000 % 0x100000000) (ishl m 16)); // assert (x' * 0x10000 % 0x100000000 == ixor (k' * 0x10000 % 0x100000000) (ishl m 16)); nat32_xor_bytewise_2_helper2 x x' t t'; () let nat32_xor_bytewise_3 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s.lo0 == s'.lo0 /\ s.lo1 == s'.lo1 /\ s.hi2 == s'.hi2 ) (ensures t.lo0 == t'.lo0 /\ t.lo1 == t'.lo1 /\ t.hi2 == t'.hi2) = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in nat32_xor_bytewise_3_helper3 k k' s s'; lemma_ishl_32 k 8; lemma_ishl_32 k' 8; lemma_ishl_32 x 8; lemma_ishl_32 x' 8; lemma_ishl_ixor_32 k m 8; lemma_ishl_ixor_32 k' m 8; nat32_xor_bytewise_3_helper2 x x' t t'; () #reset-options "--z3rlimit 50 --smtencoding.nl_arith_repr boxwrap --smtencoding.l_arith_repr boxwrap" let nat32_xor_bytewise_4 (k k' x x' m:nat32) (s s' t t':four nat8) : Lemma (requires k == four_to_nat 8 s /\ k' == four_to_nat 8 s' /\ x == four_to_nat 8 t /\ x' == four_to_nat 8 t' /\ ixor k m == x /\ ixor k' m == x' /\ s == s' ) (ensures t == t') = let Mkfour s0 s1 s2 s3 = s in let Mkfour s0' s1' s2' s3' = s' in let Mkfour t0 t1 t2 t3 = t in let Mkfour t0' t1' t2' t3' = t' in assert_norm (four_to_nat 8 t' == four_to_nat_unfold 8 t'); assert_norm (four_to_nat 8 t == four_to_nat_unfold 8 t ); () #reset-options let nat32_xor_bytewise (k k' m:nat32) (s s' t t':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ k == four_to_nat 8 (seq_to_four_LE s) /\ k' == four_to_nat 8 (seq_to_four_LE s') /\ ixor k m == four_to_nat 8 (seq_to_four_LE t) /\ ixor k' m == four_to_nat 8 (seq_to_four_LE t') /\ equal (slice s 0 n) (slice s' 0 n) ) // (ensures equal (slice t 0 n) (slice t' 0 n)) (ensures (forall (i:nat).{:pattern (index t i) \/ (index t' i)} i < n ==> index t i == index t' i)) = assert (n > 0 ==> index (slice s 0 n) 0 == index (slice s' 0 n) 0); assert (n > 1 ==> index (slice s 0 n) 1 == index (slice s' 0 n) 1); assert (n > 2 ==> index (slice s 0 n) 2 == index (slice s' 0 n) 2); assert (n > 3 ==> index (slice s 0 n) 3 == index (slice s' 0 n) 3); let x = ixor k m in let x' = ixor k' m in if n = 1 then nat32_xor_bytewise_1 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 2 then nat32_xor_bytewise_2 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 3 then nat32_xor_bytewise_3 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); if n = 4 then nat32_xor_bytewise_4 k k' x x' m (seq_to_four_LE s) (seq_to_four_LE s') (seq_to_four_LE t) (seq_to_four_LE t'); assert (equal (slice t 0 n) (slice t' 0 n)); lemma_slice_orig_index t t' 0 n; ()
{ "checked_file": "/", "dependencies": [ "Vale.Poly1305.Bitvectors.fsti.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.TypesNative_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.UInt.fsti.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": true, "source_file": "Vale.AES.GCTR.fst" }
[ { "abbrev": false, "full_module": "FStar.Seq.Properties", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> q': Vale.Def.Types_s.quad32 -> r: Vale.Def.Types_s.quad32 -> n: Prims.nat{n <= 16} -> FStar.Pervasives.Lemma (requires (let q_bytes = Vale.Def.Types_s.le_quad32_to_bytes q in let q'_bytes = Vale.Def.Types_s.le_quad32_to_bytes q' in FStar.Seq.Base.slice q_bytes 0 n == FStar.Seq.Base.slice q'_bytes 0 n)) (ensures (let q_bytes = Vale.Def.Types_s.le_quad32_to_bytes q in let q'_bytes = Vale.Def.Types_s.le_quad32_to_bytes q' in let qr_bytes = Vale.Def.Types_s.le_quad32_to_bytes (Vale.Def.Types_s.quad32_xor q r) in let q'r_bytes = Vale.Def.Types_s.le_quad32_to_bytes (Vale.Def.Types_s.quad32_xor q' r) in FStar.Seq.Base.slice qr_bytes 0 n == FStar.Seq.Base.slice q'r_bytes 0 n))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.slice", "Prims.op_LessThan", "Vale.AES.GCTR.nat32_xor_bytewise", "Vale.Def.Words_s.__proj__Mkfour__item__lo0", "Vale.Def.Types_s.nat32", "Prims.bool", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Prims.op_Subtraction", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Types_s.reverse_bytes_nat32_reveal", "Vale.Def.Types_s.quad32_xor_reveal", "Vale.AES.GCTR.lemma_slice_orig_index", "Vale.AES.Types_helpers.lemma_slices_le_quad32_to_bytes", "Vale.Def.Types_s.quad32_xor", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Vale.Def.Types_s.le_quad32_to_bytes", "Prims.eq2", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let quad32_xor_bytewise (q q' r: quad32) (n: nat{n <= 16}) : Lemma (requires (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in slice q_bytes 0 n == slice q'_bytes 0 n)) (ensures (let q_bytes = le_quad32_to_bytes q in let q'_bytes = le_quad32_to_bytes q' in let qr_bytes = le_quad32_to_bytes (quad32_xor q r) in let q'r_bytes = le_quad32_to_bytes (quad32_xor q' r) in slice qr_bytes 0 n == slice q'r_bytes 0 n)) =
let s = le_quad32_to_bytes q in let s' = le_quad32_to_bytes q' in let t = le_quad32_to_bytes (quad32_xor q r) in let t' = le_quad32_to_bytes (quad32_xor q' r) in lemma_slices_le_quad32_to_bytes q; lemma_slices_le_quad32_to_bytes q'; lemma_slices_le_quad32_to_bytes (quad32_xor q r); lemma_slices_le_quad32_to_bytes (quad32_xor q' r); lemma_slice_orig_index s s' 0 n; quad32_xor_reveal (); reverse_bytes_nat32_reveal (); if n < 4 then nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) n else (nat32_xor_bytewise q.lo0 q'.lo0 r.lo0 (slice s 0 4) (slice s' 0 4) (slice t 0 4) (slice t' 0 4) 4; if n < 8 then nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) (n - 4) else (nat32_xor_bytewise q.lo1 q'.lo1 r.lo1 (slice s 4 8) (slice s' 4 8) (slice t 4 8) (slice t' 4 8) 4; if n < 12 then nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) (n - 8) else (nat32_xor_bytewise q.hi2 q'.hi2 r.hi2 (slice s 8 12) (slice s' 8 12) (slice t 8 12) (slice t' 8 12) 4; nat32_xor_bytewise q.hi3 q'.hi3 r.hi3 (slice s 12 16) (slice s' 12 16) (slice t 12 16) (slice t' 12 16) (n - 12); ()))); assert (equal (slice t 0 n) (slice t' 0 n)); ()
false
Steel.ST.GhostReference.fst
Steel.ST.GhostReference.pts_to_injective_eq
val pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (#v0 #v1:a) (r:ref a) : STGhost unit u (pts_to r p v0 `star` pts_to r q v1) (fun _ -> pts_to r p v0 `star` pts_to r q v0) (requires True) (ensures fun _ -> v0 == v1)
val pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (#v0 #v1:a) (r:ref a) : STGhost unit u (pts_to r p v0 `star` pts_to r q v1) (fun _ -> pts_to r p v0 `star` pts_to r q v0) (requires True) (ensures fun _ -> v0 == v1)
let pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (#v0 #v1:a) (r:ref a) : STGhost unit u (pts_to r p v0 `star` pts_to r q v1) (fun _ -> pts_to r p v0 `star` pts_to r q v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1))
{ "file_name": "lib/steel/Steel.ST.GhostReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 76, "end_line": 47, "start_col": 0, "start_line": 36 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.GhostReference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference [@@ erasable] let ref (a:Type u#0) : Type u#0 = R.ghost_ref a let dummy_ref a = R.dummy_ghost_ref a let pts_to (#a:_) (r:ref a) (p:perm) ([@@@smt_fallback] v:a) : vprop = R.ghost_pts_to r p v
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.GhostReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "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
r: Steel.ST.GhostReference.ref a -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.ST.GhostReference.ref", "Steel.ST.Coercions.coerce_ghost", "Prims.unit", "Steel.Effect.Common.star", "Steel.Reference.ghost_pts_to", "FStar.Ghost.reveal", "FStar.Ghost.hide", "Steel.Effect.Common.vprop", "Prims.l_True", "Prims.eq2", "FStar.Ghost.erased", "Steel.Reference.ghost_pts_to_injective_eq", "Steel.ST.GhostReference.pts_to" ]
[]
false
true
false
false
false
let pts_to_injective_eq (#a #u #p #q: _) (#v0 #v1: a) (r: ref a) : STGhost unit u ((pts_to r p v0) `star` (pts_to r q v1)) (fun _ -> (pts_to r p v0) `star` (pts_to r q v0)) (requires True) (ensures fun _ -> v0 == v1) =
coerce_ghost (fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1))
false
FStar.FiniteSet.Base.fst
FStar.FiniteSet.Base.cardinality_matches_difference_plus_intersection_lemma
val cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1 s2: set a) : Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2))
val cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1 s2: set a) : Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2))
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) = union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2); assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
{ "file_name": "ulib/FStar.FiniteSet.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 326, "start_col": 0, "start_line": 323 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite sets as they're modeled in Dafny. @summary Type and functions for modeling finite sets *) module FStar.FiniteSet.Base module FLT = FStar.List.Tot open FStar.FunctionalExtensionality let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop = forall x. f x == x `FLT.mem` xs // Finite sets type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs} /// We represent the Dafny function [] on sets with `mem`: let mem (#a: eqtype) (x: a) (s: set a) : bool = s x /// We represent the Dafny function `Set#Card` with `cardinality`: /// /// function Set#Card<T>(Set T): int; let rec remove_repeats (#a: eqtype) (xs: list a) : (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) = match xs with | [] -> [] | hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl' let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) = remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s)) [@"opaque_to_smt"] let cardinality (#a: eqtype) (s: set a) : GTot nat = FLT.length (set_as_list s) let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a)) : Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) = Classical.exists_intro (fun xs -> f `has_elements` xs) xs; f /// We represent the Dafny function `Set#Empty` with `empty`: let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) [] /// We represent the Dafny function `Set#UnionOne` with `insert`: /// /// function Set#UnionOne<T>(Set T, T): Set T; let insert (#a: eqtype) (x: a) (s: set a): set a = intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s) /// We represent the Dafny function `Set#Singleton` with `singleton`: /// /// function Set#Singleton<T>(T): Set T; let singleton (#a: eqtype) (x: a) : set a = insert x emptyset /// We represent the Dafny function `Set#Union` with `union`: /// /// function Set#Union<T>(Set T, Set T): Set T; let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) = match xs with | [] -> ys | hd :: tl -> hd :: union_lists tl ys let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) = intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Intersection` with `intersection`: /// /// function Set#Intersection<T>(Set T, Set T): Set T; let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) = match xs with | [] -> [] | hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs' let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Difference` with `difference`: /// /// function Set#Difference<T>(Set T, Set T): Set T; let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) = match xs with | [] -> [] | hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs' let difference (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Subset` with `subset`: /// /// function Set#Subset<T>(Set T, Set T): bool; let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. (s1 x = true) ==> (s2 x = true) /// We represent the Dafny function `Set#Equal` with `equal`: /// /// function Set#Equal<T>(Set T, Set T): bool; let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 = feq s1 s2 /// We represent the Dafny function `Set#Disjoint` with `disjoint`: /// /// function Set#Disjoint<T>(Set T, Set T): bool; let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. not (s1 x && s2 x) /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) = Cons?.hd (set_as_list s) /// We now prove each of the facts that comprise `all_finite_set_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that /// requires a helper lemma, which we call `xxx_helper`. let empty_set_contains_no_elements_lemma () : Lemma (empty_set_contains_no_elements_fact) = () let length_zero_lemma () : Lemma (length_zero_fact) = introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s)) with ( reveal_opaque (`%cardinality) (cardinality #a); introduce cardinality s = 0 ==> s == emptyset with _. assert (feq s emptyset); introduce s == emptyset ==> cardinality s = 0 with _. assert (set_as_list s == []); introduce cardinality s <> 0 ==> _ with _. introduce exists x. mem x s with (Cons?.hd (set_as_list s)) and ()) let singleton_contains_argument_lemma () : Lemma (singleton_contains_argument_fact) = () let singleton_contains_lemma () : Lemma (singleton_contains_fact) = () let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a) : Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r)) (ensures remove_repeats xs == [r]) = match xs with | [x] -> () | hd :: tl -> assert (Cons?.hd tl = r); singleton_cardinality_helper r tl let singleton_cardinality_lemma () : Lemma (singleton_cardinality_fact) = introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1 with ( reveal_opaque (`%cardinality) (cardinality #a); singleton_cardinality_helper r (set_as_list (singleton r)) ) let insert_lemma () : Lemma (insert_fact) = () let insert_contains_argument_lemma () : Lemma (insert_contains_argument_fact) = () let insert_contains_lemma () : Lemma (insert_contains_fact) = () let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs}) : (xs': list a{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) = match xs with | hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a) : Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2)) (ensures FLT.length s1 = FLT.length s2) = match s1 with | [] -> () | hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s with introduce mem x s ==> cardinality (insert x s) = cardinality s with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s)) ) let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s)) ) let union_contains_lemma () : Lemma (union_contains_fact) = () let union_contains_element_from_first_argument_lemma () : Lemma (union_contains_element_from_first_argument_fact) = () let union_contains_element_from_second_argument_lemma () : Lemma (union_contains_element_from_second_argument_fact) = () let union_of_disjoint_lemma () : Lemma (union_of_disjoint_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with _. ( assert (feq (difference (union s1 s2) s1) s2); assert (feq (difference (union s1 s2) s2) s1) ) let intersection_contains_lemma () : Lemma (intersection_contains_fact) = () let union_idempotent_right_lemma () : Lemma (union_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2 with assert (feq (union (union s1 s2) s2) (union s1 s2)) let union_idempotent_left_lemma () : Lemma (union_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2 with assert (feq (union s1 (union s1 s2)) (union s1 s2)) let intersection_idempotent_right_lemma () : Lemma (intersection_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2 with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2)) let intersection_idempotent_left_lemma () : Lemma (intersection_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2 with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2)) let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a) : Lemma (requires list_nonrepeating xs1 /\ list_nonrepeating xs2 /\ list_nonrepeating xs3 /\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2)) /\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2)) (ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) = match xs1 with | [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3 | hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3) let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (requires disjoint s1 s2) (ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) = reveal_opaque (`%cardinality) (cardinality #a); union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2)) let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a) : Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3) (ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) = union_of_disjoint_sets_cardinality_lemma s1 s2; union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteSet.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s1: FStar.FiniteSet.Base.set a -> s2: FStar.FiniteSet.Base.set a -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.cardinality s1 = FStar.FiniteSet.Base.cardinality (FStar.FiniteSet.Base.difference s1 s2) + FStar.FiniteSet.Base.cardinality (FStar.FiniteSet.Base.intersection s1 s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.FiniteSet.Base.set", "Prims._assert", "FStar.FunctionalExtensionality.feq", "Prims.bool", "FStar.FiniteSet.Base.union", "FStar.FiniteSet.Base.difference", "FStar.FiniteSet.Base.intersection", "Prims.unit", "FStar.FiniteSet.Base.union_of_disjoint_sets_cardinality_lemma", "Prims.l_True", "Prims.squash", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.FiniteSet.Base.cardinality", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1 s2: set a) : Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) =
union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2); assert (feq s1 (union (difference s1 s2) (intersection s1 s2)))
false
FStar.FiniteSet.Base.fst
FStar.FiniteSet.Base.union_idempotent_left_lemma
val union_idempotent_left_lemma: Prims.unit -> Lemma (union_idempotent_left_fact)
val union_idempotent_left_lemma: Prims.unit -> Lemma (union_idempotent_left_fact)
let union_idempotent_left_lemma () : Lemma (union_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2 with assert (feq (union s1 (union s1 s2)) (union s1 s2))
{ "file_name": "ulib/FStar.FiniteSet.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 288, "start_col": 0, "start_line": 285 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite sets as they're modeled in Dafny. @summary Type and functions for modeling finite sets *) module FStar.FiniteSet.Base module FLT = FStar.List.Tot open FStar.FunctionalExtensionality let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop = forall x. f x == x `FLT.mem` xs // Finite sets type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs} /// We represent the Dafny function [] on sets with `mem`: let mem (#a: eqtype) (x: a) (s: set a) : bool = s x /// We represent the Dafny function `Set#Card` with `cardinality`: /// /// function Set#Card<T>(Set T): int; let rec remove_repeats (#a: eqtype) (xs: list a) : (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) = match xs with | [] -> [] | hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl' let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) = remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s)) [@"opaque_to_smt"] let cardinality (#a: eqtype) (s: set a) : GTot nat = FLT.length (set_as_list s) let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a)) : Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) = Classical.exists_intro (fun xs -> f `has_elements` xs) xs; f /// We represent the Dafny function `Set#Empty` with `empty`: let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) [] /// We represent the Dafny function `Set#UnionOne` with `insert`: /// /// function Set#UnionOne<T>(Set T, T): Set T; let insert (#a: eqtype) (x: a) (s: set a): set a = intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s) /// We represent the Dafny function `Set#Singleton` with `singleton`: /// /// function Set#Singleton<T>(T): Set T; let singleton (#a: eqtype) (x: a) : set a = insert x emptyset /// We represent the Dafny function `Set#Union` with `union`: /// /// function Set#Union<T>(Set T, Set T): Set T; let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) = match xs with | [] -> ys | hd :: tl -> hd :: union_lists tl ys let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) = intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Intersection` with `intersection`: /// /// function Set#Intersection<T>(Set T, Set T): Set T; let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) = match xs with | [] -> [] | hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs' let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Difference` with `difference`: /// /// function Set#Difference<T>(Set T, Set T): Set T; let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) = match xs with | [] -> [] | hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs' let difference (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Subset` with `subset`: /// /// function Set#Subset<T>(Set T, Set T): bool; let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. (s1 x = true) ==> (s2 x = true) /// We represent the Dafny function `Set#Equal` with `equal`: /// /// function Set#Equal<T>(Set T, Set T): bool; let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 = feq s1 s2 /// We represent the Dafny function `Set#Disjoint` with `disjoint`: /// /// function Set#Disjoint<T>(Set T, Set T): bool; let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. not (s1 x && s2 x) /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) = Cons?.hd (set_as_list s) /// We now prove each of the facts that comprise `all_finite_set_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that /// requires a helper lemma, which we call `xxx_helper`. let empty_set_contains_no_elements_lemma () : Lemma (empty_set_contains_no_elements_fact) = () let length_zero_lemma () : Lemma (length_zero_fact) = introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s)) with ( reveal_opaque (`%cardinality) (cardinality #a); introduce cardinality s = 0 ==> s == emptyset with _. assert (feq s emptyset); introduce s == emptyset ==> cardinality s = 0 with _. assert (set_as_list s == []); introduce cardinality s <> 0 ==> _ with _. introduce exists x. mem x s with (Cons?.hd (set_as_list s)) and ()) let singleton_contains_argument_lemma () : Lemma (singleton_contains_argument_fact) = () let singleton_contains_lemma () : Lemma (singleton_contains_fact) = () let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a) : Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r)) (ensures remove_repeats xs == [r]) = match xs with | [x] -> () | hd :: tl -> assert (Cons?.hd tl = r); singleton_cardinality_helper r tl let singleton_cardinality_lemma () : Lemma (singleton_cardinality_fact) = introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1 with ( reveal_opaque (`%cardinality) (cardinality #a); singleton_cardinality_helper r (set_as_list (singleton r)) ) let insert_lemma () : Lemma (insert_fact) = () let insert_contains_argument_lemma () : Lemma (insert_contains_argument_fact) = () let insert_contains_lemma () : Lemma (insert_contains_fact) = () let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs}) : (xs': list a{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) = match xs with | hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a) : Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2)) (ensures FLT.length s1 = FLT.length s2) = match s1 with | [] -> () | hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s with introduce mem x s ==> cardinality (insert x s) = cardinality s with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s)) ) let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s)) ) let union_contains_lemma () : Lemma (union_contains_fact) = () let union_contains_element_from_first_argument_lemma () : Lemma (union_contains_element_from_first_argument_fact) = () let union_contains_element_from_second_argument_lemma () : Lemma (union_contains_element_from_second_argument_fact) = () let union_of_disjoint_lemma () : Lemma (union_of_disjoint_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with _. ( assert (feq (difference (union s1 s2) s1) s2); assert (feq (difference (union s1 s2) s2) s1) ) let intersection_contains_lemma () : Lemma (intersection_contains_fact) = () let union_idempotent_right_lemma () : Lemma (union_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2 with assert (feq (union (union s1 s2) s2) (union s1 s2))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteSet.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
_: Prims.unit -> FStar.Pervasives.Lemma (ensures FStar.FiniteSet.Base.union_idempotent_left_fact)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.Sugar.forall_intro", "Prims.eqtype", "Prims.l_Forall", "FStar.FiniteSet.Base.set", "Prims.eq2", "FStar.FiniteSet.Base.union", "Prims._assert", "FStar.FunctionalExtensionality.feq", "Prims.bool", "Prims.squash", "Prims.l_True", "FStar.FiniteSet.Base.union_idempotent_left_fact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let union_idempotent_left_lemma () : Lemma (union_idempotent_left_fact) =
introduce forall (a: eqtype) (s1: set a) (s2: set a) . union s1 (union s1 s2) == union s1 s2 with assert (feq (union s1 (union s1 s2)) (union s1 s2))
false
FStar.FiniteSet.Base.fst
FStar.FiniteSet.Base.insert_remove_helper
val insert_remove_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s) (ensures insert x (remove x s) == s)
val insert_remove_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s) (ensures insert x (remove x s) == s)
let insert_remove_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s) (ensures insert x (remove x s) == s) = assert (feq s (insert x (remove x s)))
{ "file_name": "ulib/FStar.FiniteSet.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 413, "start_col": 0, "start_line": 410 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite sets as they're modeled in Dafny. @summary Type and functions for modeling finite sets *) module FStar.FiniteSet.Base module FLT = FStar.List.Tot open FStar.FunctionalExtensionality let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop = forall x. f x == x `FLT.mem` xs // Finite sets type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs} /// We represent the Dafny function [] on sets with `mem`: let mem (#a: eqtype) (x: a) (s: set a) : bool = s x /// We represent the Dafny function `Set#Card` with `cardinality`: /// /// function Set#Card<T>(Set T): int; let rec remove_repeats (#a: eqtype) (xs: list a) : (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) = match xs with | [] -> [] | hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl' let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) = remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s)) [@"opaque_to_smt"] let cardinality (#a: eqtype) (s: set a) : GTot nat = FLT.length (set_as_list s) let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a)) : Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) = Classical.exists_intro (fun xs -> f `has_elements` xs) xs; f /// We represent the Dafny function `Set#Empty` with `empty`: let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) [] /// We represent the Dafny function `Set#UnionOne` with `insert`: /// /// function Set#UnionOne<T>(Set T, T): Set T; let insert (#a: eqtype) (x: a) (s: set a): set a = intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s) /// We represent the Dafny function `Set#Singleton` with `singleton`: /// /// function Set#Singleton<T>(T): Set T; let singleton (#a: eqtype) (x: a) : set a = insert x emptyset /// We represent the Dafny function `Set#Union` with `union`: /// /// function Set#Union<T>(Set T, Set T): Set T; let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) = match xs with | [] -> ys | hd :: tl -> hd :: union_lists tl ys let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) = intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Intersection` with `intersection`: /// /// function Set#Intersection<T>(Set T, Set T): Set T; let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) = match xs with | [] -> [] | hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs' let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Difference` with `difference`: /// /// function Set#Difference<T>(Set T, Set T): Set T; let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) = match xs with | [] -> [] | hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs' let difference (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Subset` with `subset`: /// /// function Set#Subset<T>(Set T, Set T): bool; let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. (s1 x = true) ==> (s2 x = true) /// We represent the Dafny function `Set#Equal` with `equal`: /// /// function Set#Equal<T>(Set T, Set T): bool; let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 = feq s1 s2 /// We represent the Dafny function `Set#Disjoint` with `disjoint`: /// /// function Set#Disjoint<T>(Set T, Set T): bool; let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. not (s1 x && s2 x) /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) = Cons?.hd (set_as_list s) /// We now prove each of the facts that comprise `all_finite_set_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that /// requires a helper lemma, which we call `xxx_helper`. let empty_set_contains_no_elements_lemma () : Lemma (empty_set_contains_no_elements_fact) = () let length_zero_lemma () : Lemma (length_zero_fact) = introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s)) with ( reveal_opaque (`%cardinality) (cardinality #a); introduce cardinality s = 0 ==> s == emptyset with _. assert (feq s emptyset); introduce s == emptyset ==> cardinality s = 0 with _. assert (set_as_list s == []); introduce cardinality s <> 0 ==> _ with _. introduce exists x. mem x s with (Cons?.hd (set_as_list s)) and ()) let singleton_contains_argument_lemma () : Lemma (singleton_contains_argument_fact) = () let singleton_contains_lemma () : Lemma (singleton_contains_fact) = () let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a) : Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r)) (ensures remove_repeats xs == [r]) = match xs with | [x] -> () | hd :: tl -> assert (Cons?.hd tl = r); singleton_cardinality_helper r tl let singleton_cardinality_lemma () : Lemma (singleton_cardinality_fact) = introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1 with ( reveal_opaque (`%cardinality) (cardinality #a); singleton_cardinality_helper r (set_as_list (singleton r)) ) let insert_lemma () : Lemma (insert_fact) = () let insert_contains_argument_lemma () : Lemma (insert_contains_argument_fact) = () let insert_contains_lemma () : Lemma (insert_contains_fact) = () let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs}) : (xs': list a{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) = match xs with | hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a) : Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2)) (ensures FLT.length s1 = FLT.length s2) = match s1 with | [] -> () | hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s with introduce mem x s ==> cardinality (insert x s) = cardinality s with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s)) ) let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s)) ) let union_contains_lemma () : Lemma (union_contains_fact) = () let union_contains_element_from_first_argument_lemma () : Lemma (union_contains_element_from_first_argument_fact) = () let union_contains_element_from_second_argument_lemma () : Lemma (union_contains_element_from_second_argument_fact) = () let union_of_disjoint_lemma () : Lemma (union_of_disjoint_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with _. ( assert (feq (difference (union s1 s2) s1) s2); assert (feq (difference (union s1 s2) s2) s1) ) let intersection_contains_lemma () : Lemma (intersection_contains_fact) = () let union_idempotent_right_lemma () : Lemma (union_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2 with assert (feq (union (union s1 s2) s2) (union s1 s2)) let union_idempotent_left_lemma () : Lemma (union_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2 with assert (feq (union s1 (union s1 s2)) (union s1 s2)) let intersection_idempotent_right_lemma () : Lemma (intersection_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2 with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2)) let intersection_idempotent_left_lemma () : Lemma (intersection_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2 with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2)) let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a) : Lemma (requires list_nonrepeating xs1 /\ list_nonrepeating xs2 /\ list_nonrepeating xs3 /\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2)) /\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2)) (ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) = match xs1 with | [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3 | hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3) let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (requires disjoint s1 s2) (ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) = reveal_opaque (`%cardinality) (cardinality #a); union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2)) let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a) : Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3) (ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) = union_of_disjoint_sets_cardinality_lemma s1 s2; union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3 let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) = union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2); assert (feq s1 (union (difference s1 s2) (intersection s1 s2))) let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a) : Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) = assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1))) let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a) : Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) = cardinality_matches_difference_plus_intersection_lemma s1 s2; cardinality_matches_difference_plus_intersection_lemma s2 s1; union_is_differences_and_intersection s1 s2; union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1); assert (feq (intersection s1 s2) (intersection s2 s1)) let intersection_cardinality_lemma () : Lemma (intersection_cardinality_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2 with intersection_cardinality_helper a s1 s2 let difference_contains_lemma () : Lemma (difference_contains_fact) = () let difference_doesnt_include_lemma () : Lemma (difference_doesnt_include_fact) = () let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a) : Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2) /\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) = union_is_differences_and_intersection s1 s2; union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1); cardinality_matches_difference_plus_intersection_lemma s1 s2 let difference_cardinality_lemma () : Lemma (difference_cardinality_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2) /\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2) with difference_cardinality_helper a s1 s2 let subset_helper (a: eqtype) (s1: set a) (s2: set a) : Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) = introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2 with _. introduce forall x. s1 x = true ==> s2 x = true with assert (mem x s1 = s1 x) let subset_lemma () : Lemma (subset_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) with subset_helper a s1 s2 let equal_lemma () : Lemma (equal_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) with ( introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2 with _. introduce forall x. s1 x = true <==> s2 x = true with assert (mem x s1 = s1 x /\ mem x s2 = s2 x) ) let equal_extensionality_lemma () : Lemma (equal_extensionality_fact) = () let disjoint_lemma () : Lemma (disjoint_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) with ( introduce (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint s1 s2 with _. ( introduce forall x. not (s1 x && s2 x) with assert (not (mem x s1) \/ not (mem x s2)) ) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteSet.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
a: Prims.eqtype -> x: a -> s: FStar.FiniteSet.Base.set a -> FStar.Pervasives.Lemma (requires FStar.FiniteSet.Base.mem x s) (ensures FStar.FiniteSet.Base.insert x (FStar.FiniteSet.Base.remove x s) == s)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.FiniteSet.Base.set", "Prims._assert", "FStar.FunctionalExtensionality.feq", "Prims.bool", "FStar.FiniteSet.Base.insert", "FStar.FiniteSet.Base.remove", "Prims.unit", "Prims.b2t", "FStar.FiniteSet.Base.mem", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let insert_remove_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s) (ensures insert x (remove x s) == s) =
assert (feq s (insert x (remove x s)))
false
Steel.ST.GhostReference.fst
Steel.ST.GhostReference.read
val read (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ref a) : STGhost (erased a) u (pts_to r p v) (fun x -> pts_to r p x) (requires True) (ensures fun x -> x == v)
val read (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ref a) : STGhost (erased a) u (pts_to r p v) (fun x -> pts_to r p x) (requires True) (ensures fun x -> x == v)
let read (#a:Type) (#u:_) (#p:perm) (#v:erased a) (r:ref a) : STGhost (erased a) u (pts_to r p v) (fun x -> pts_to r p x) (requires True) (ensures fun x -> x == v) = let y = coerce_ghost (fun _ -> R.ghost_read_pt r) in y
{ "file_name": "lib/steel/Steel.ST.GhostReference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 70, "start_col": 0, "start_line": 59 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.GhostReference open FStar.Ghost open Steel.ST.Util open Steel.ST.Coercions module R = Steel.Reference [@@ erasable] let ref (a:Type u#0) : Type u#0 = R.ghost_ref a let dummy_ref a = R.dummy_ghost_ref a let pts_to (#a:_) (r:ref a) (p:perm) ([@@@smt_fallback] v:a) : vprop = R.ghost_pts_to r p v let pts_to_injective_eq (#a:_) (#u:_) (#p #q:_) (#v0 #v1:a) (r:ref a) : STGhost unit u (pts_to r p v0 `star` pts_to r q v1) (fun _ -> pts_to r p v0 `star` pts_to r q v0) (requires True) (ensures fun _ -> v0 == v1) = coerce_ghost (fun _ -> R.ghost_pts_to_injective_eq #a #u #p #q r (hide v0) (hide v1)) let pts_to_perm r = coerce_ghost (fun _ -> R.ghost_pts_to_perm r) let alloc (#a:Type) (#u:_) (x:erased a) : STGhostT (ref a) u emp (fun r -> pts_to r full_perm x) = coerce_ghost (fun _ -> R.ghost_alloc_pt x)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Reference.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.GhostReference.fst" }
[ { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "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
r: Steel.ST.GhostReference.ref a -> Steel.ST.Effect.Ghost.STGhost (FStar.Ghost.erased a)
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "Steel.ST.GhostReference.ref", "Steel.ST.Coercions.coerce_ghost", "Steel.Reference.ghost_pts_to", "FStar.Ghost.reveal", "Steel.Effect.Common.vprop", "Prims.l_True", "Prims.eq2", "Prims.unit", "Steel.Reference.ghost_read_pt", "Steel.ST.GhostReference.pts_to" ]
[]
false
true
false
false
false
let read (#a: Type) (#u: _) (#p: perm) (#v: erased a) (r: ref a) : STGhost (erased a) u (pts_to r p v) (fun x -> pts_to r p x) (requires True) (ensures fun x -> x == v) =
let y = coerce_ghost (fun _ -> R.ghost_read_pt r) in y
false
FStar.FiniteSet.Base.fst
FStar.FiniteSet.Base.remove_insert_helper
val remove_insert_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s = false) (ensures remove x (insert x s) == s)
val remove_insert_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s = false) (ensures remove x (insert x s) == s)
let remove_insert_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s = false) (ensures remove x (insert x s) == s) = assert (feq s (remove x (insert x s)))
{ "file_name": "ulib/FStar.FiniteSet.Base.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 425, "start_col": 0, "start_line": 422 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module declares a type and functions used for modeling finite sets as they're modeled in Dafny. @summary Type and functions for modeling finite sets *) module FStar.FiniteSet.Base module FLT = FStar.List.Tot open FStar.FunctionalExtensionality let has_elements (#a: eqtype) (f: a ^-> bool) (xs: list a): prop = forall x. f x == x `FLT.mem` xs // Finite sets type set (a: eqtype) = f:(a ^-> bool){exists xs. f `has_elements` xs} /// We represent the Dafny function [] on sets with `mem`: let mem (#a: eqtype) (x: a) (s: set a) : bool = s x /// We represent the Dafny function `Set#Card` with `cardinality`: /// /// function Set#Card<T>(Set T): int; let rec remove_repeats (#a: eqtype) (xs: list a) : (ys: list a{list_nonrepeating ys /\ (forall y. FLT.mem y ys <==> FLT.mem y xs)}) = match xs with | [] -> [] | hd :: tl -> let tl' = remove_repeats tl in if FLT.mem hd tl then tl' else hd :: tl' let set_as_list (#a: eqtype) (s: set a): GTot (xs: list a{list_nonrepeating xs /\ (forall x. FLT.mem x xs = mem x s)}) = remove_repeats (FStar.IndefiniteDescription.indefinite_description_ghost (list a) (fun xs -> forall x. FLT.mem x xs = mem x s)) [@"opaque_to_smt"] let cardinality (#a: eqtype) (s: set a) : GTot nat = FLT.length (set_as_list s) let intro_set (#a: eqtype) (f: a ^-> bool) (xs: Ghost.erased (list a)) : Pure (set a) (requires f `has_elements` xs) (ensures fun _ -> True) = Classical.exists_intro (fun xs -> f `has_elements` xs) xs; f /// We represent the Dafny function `Set#Empty` with `empty`: let emptyset (#a: eqtype): set a = intro_set (on_dom a (fun _ -> false)) [] /// We represent the Dafny function `Set#UnionOne` with `insert`: /// /// function Set#UnionOne<T>(Set T, T): Set T; let insert (#a: eqtype) (x: a) (s: set a): set a = intro_set (on_dom _ (fun x' -> x = x' || s x')) (x :: set_as_list s) /// We represent the Dafny function `Set#Singleton` with `singleton`: /// /// function Set#Singleton<T>(T): Set T; let singleton (#a: eqtype) (x: a) : set a = insert x emptyset /// We represent the Dafny function `Set#Union` with `union`: /// /// function Set#Union<T>(Set T, Set T): Set T; let rec union_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs \/ FLT.mem z ys}) = match xs with | [] -> ys | hd :: tl -> hd :: union_lists tl ys let union (#a: eqtype) (s1: set a) (s2: set a) : (set a) = intro_set (on_dom a (fun x -> s1 x || s2 x)) (union_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Intersection` with `intersection`: /// /// function Set#Intersection<T>(Set T, Set T): Set T; let rec intersect_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ FLT.mem z ys}) = match xs with | [] -> [] | hd :: tl -> let zs' = intersect_lists tl ys in if FLT.mem hd ys then hd :: zs' else zs' let intersection (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && s2 x)) (intersect_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Difference` with `difference`: /// /// function Set#Difference<T>(Set T, Set T): Set T; let rec difference_lists (#a: eqtype) (xs: list a) (ys: list a) : (zs: list a{forall z. FLT.mem z zs <==> FLT.mem z xs /\ ~(FLT.mem z ys)}) = match xs with | [] -> [] | hd :: tl -> let zs' = difference_lists tl ys in if FLT.mem hd ys then zs' else hd :: zs' let difference (#a: eqtype) (s1: set a) (s2: set a) : set a = intro_set (on_dom a (fun x -> s1 x && not (s2 x))) (difference_lists (set_as_list s1) (set_as_list s2)) /// We represent the Dafny function `Set#Subset` with `subset`: /// /// function Set#Subset<T>(Set T, Set T): bool; let subset (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. (s1 x = true) ==> (s2 x = true) /// We represent the Dafny function `Set#Equal` with `equal`: /// /// function Set#Equal<T>(Set T, Set T): bool; let equal (#a: eqtype) (s1: set a) (s2: set a) : Type0 = feq s1 s2 /// We represent the Dafny function `Set#Disjoint` with `disjoint`: /// /// function Set#Disjoint<T>(Set T, Set T): bool; let disjoint (#a: eqtype) (s1: set a) (s2: set a) : Type0 = forall x. not (s1 x && s2 x) /// We represent the Dafny choice operator by `choose`: /// /// var x: T :| x in s; let choose (#a: eqtype) (s: set a{exists x. mem x s}) : GTot (x: a{mem x s}) = Cons?.hd (set_as_list s) /// We now prove each of the facts that comprise `all_finite_set_facts`. /// For fact `xxx_fact`, we prove it with `xxx_lemma`. Sometimes, that /// requires a helper lemma, which we call `xxx_helper`. let empty_set_contains_no_elements_lemma () : Lemma (empty_set_contains_no_elements_fact) = () let length_zero_lemma () : Lemma (length_zero_fact) = introduce forall (a: eqtype) (s: set a). (cardinality s = 0 <==> s == emptyset) /\ (cardinality s <> 0 <==> (exists x. mem x s)) with ( reveal_opaque (`%cardinality) (cardinality #a); introduce cardinality s = 0 ==> s == emptyset with _. assert (feq s emptyset); introduce s == emptyset ==> cardinality s = 0 with _. assert (set_as_list s == []); introduce cardinality s <> 0 ==> _ with _. introduce exists x. mem x s with (Cons?.hd (set_as_list s)) and ()) let singleton_contains_argument_lemma () : Lemma (singleton_contains_argument_fact) = () let singleton_contains_lemma () : Lemma (singleton_contains_fact) = () let rec singleton_cardinality_helper (#a: eqtype) (r: a) (xs: list a) : Lemma (requires FLT.mem r xs /\ (forall x. FLT.mem x xs <==> x = r)) (ensures remove_repeats xs == [r]) = match xs with | [x] -> () | hd :: tl -> assert (Cons?.hd tl = r); singleton_cardinality_helper r tl let singleton_cardinality_lemma () : Lemma (singleton_cardinality_fact) = introduce forall (a: eqtype) (r: a). cardinality (singleton r) = 1 with ( reveal_opaque (`%cardinality) (cardinality #a); singleton_cardinality_helper r (set_as_list (singleton r)) ) let insert_lemma () : Lemma (insert_fact) = () let insert_contains_argument_lemma () : Lemma (insert_contains_argument_fact) = () let insert_contains_lemma () : Lemma (insert_contains_fact) = () let rec remove_from_nonrepeating_list (#a: eqtype) (x: a) (xs: list a{FLT.mem x xs /\ list_nonrepeating xs}) : (xs': list a{ list_nonrepeating xs' /\ FLT.length xs' = FLT.length xs - 1 /\ (forall y. FLT.mem y xs' <==> FLT.mem y xs /\ y <> x)}) = match xs with | hd :: tl -> if x = hd then tl else hd :: (remove_from_nonrepeating_list x tl) let rec nonrepeating_lists_with_same_elements_have_same_length (#a: eqtype) (s1: list a) (s2: list a) : Lemma (requires list_nonrepeating s1 /\ list_nonrepeating s2 /\ (forall x. FLT.mem x s1 <==> FLT.mem x s2)) (ensures FLT.length s1 = FLT.length s2) = match s1 with | [] -> () | hd :: tl -> nonrepeating_lists_with_same_elements_have_same_length tl (remove_from_nonrepeating_list hd s2) let insert_member_cardinality_lemma () : Lemma (insert_member_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). mem x s ==> cardinality (insert x s) = cardinality s with introduce mem x s ==> cardinality (insert x s) = cardinality s with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (set_as_list s) (set_as_list (insert x s)) ) let insert_nonmember_cardinality_lemma () : Lemma (insert_nonmember_cardinality_fact) = introduce forall (a: eqtype) (s: set a) (x: a). not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with introduce not (mem x s) ==> cardinality (insert x s) = cardinality s + 1 with _. ( reveal_opaque (`%cardinality) (cardinality #a); nonrepeating_lists_with_same_elements_have_same_length (x :: (set_as_list s)) (set_as_list (insert x s)) ) let union_contains_lemma () : Lemma (union_contains_fact) = () let union_contains_element_from_first_argument_lemma () : Lemma (union_contains_element_from_first_argument_fact) = () let union_contains_element_from_second_argument_lemma () : Lemma (union_contains_element_from_second_argument_fact) = () let union_of_disjoint_lemma () : Lemma (union_of_disjoint_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with introduce disjoint s1 s2 ==> difference (union s1 s2) s1 == s2 /\ difference (union s1 s2) s2 == s1 with _. ( assert (feq (difference (union s1 s2) s1) s2); assert (feq (difference (union s1 s2) s2) s1) ) let intersection_contains_lemma () : Lemma (intersection_contains_fact) = () let union_idempotent_right_lemma () : Lemma (union_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union (union s1 s2) s2 == union s1 s2 with assert (feq (union (union s1 s2) s2) (union s1 s2)) let union_idempotent_left_lemma () : Lemma (union_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). union s1 (union s1 s2) == union s1 s2 with assert (feq (union s1 (union s1 s2)) (union s1 s2)) let intersection_idempotent_right_lemma () : Lemma (intersection_idempotent_right_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection (intersection s1 s2) s2 == intersection s1 s2 with assert (feq (intersection (intersection s1 s2) s2) (intersection s1 s2)) let intersection_idempotent_left_lemma () : Lemma (intersection_idempotent_left_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). intersection s1 (intersection s1 s2) == intersection s1 s2 with assert (feq (intersection s1 (intersection s1 s2)) (intersection s1 s2)) let rec union_of_disjoint_nonrepeating_lists_length_lemma (#a: eqtype) (xs1: list a) (xs2: list a) (xs3: list a) : Lemma (requires list_nonrepeating xs1 /\ list_nonrepeating xs2 /\ list_nonrepeating xs3 /\ (forall x. ~(FLT.mem x xs1 /\ FLT.mem x xs2)) /\ (forall x. FLT.mem x xs3 <==> FLT.mem x xs1 \/ FLT.mem x xs2)) (ensures FLT.length xs3 = FLT.length xs1 + FLT.length xs2) = match xs1 with | [] -> nonrepeating_lists_with_same_elements_have_same_length xs2 xs3 | hd :: tl -> union_of_disjoint_nonrepeating_lists_length_lemma tl xs2 (remove_from_nonrepeating_list hd xs3) let union_of_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (requires disjoint s1 s2) (ensures cardinality (union s1 s2) = cardinality s1 + cardinality s2) = reveal_opaque (`%cardinality) (cardinality #a); union_of_disjoint_nonrepeating_lists_length_lemma (set_as_list s1) (set_as_list s2) (set_as_list (union s1 s2)) let union_of_three_disjoint_sets_cardinality_lemma (#a: eqtype) (s1: set a) (s2: set a) (s3: set a) : Lemma (requires disjoint s1 s2 /\ disjoint s2 s3 /\ disjoint s1 s3) (ensures cardinality (union (union s1 s2) s3) = cardinality s1 + cardinality s2 + cardinality s3) = union_of_disjoint_sets_cardinality_lemma s1 s2; union_of_disjoint_sets_cardinality_lemma (union s1 s2) s3 let cardinality_matches_difference_plus_intersection_lemma (#a: eqtype) (s1: set a) (s2: set a) : Lemma (ensures cardinality s1 = cardinality (difference s1 s2) + cardinality (intersection s1 s2)) = union_of_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2); assert (feq s1 (union (difference s1 s2) (intersection s1 s2))) let union_is_differences_and_intersection (#a: eqtype) (s1: set a) (s2: set a) : Lemma (union s1 s2 == union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1)) = assert (feq (union s1 s2) (union (union (difference s1 s2) (intersection s1 s2)) (difference s2 s1))) let intersection_cardinality_helper (a: eqtype) (s1: set a) (s2: set a) : Lemma (cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2) = cardinality_matches_difference_plus_intersection_lemma s1 s2; cardinality_matches_difference_plus_intersection_lemma s2 s1; union_is_differences_and_intersection s1 s2; union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1); assert (feq (intersection s1 s2) (intersection s2 s1)) let intersection_cardinality_lemma () : Lemma (intersection_cardinality_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). cardinality (union s1 s2) + cardinality (intersection s1 s2) = cardinality s1 + cardinality s2 with intersection_cardinality_helper a s1 s2 let difference_contains_lemma () : Lemma (difference_contains_fact) = () let difference_doesnt_include_lemma () : Lemma (difference_doesnt_include_fact) = () let difference_cardinality_helper (a: eqtype) (s1: set a) (s2: set a) : Lemma ( cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2) /\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2)) = union_is_differences_and_intersection s1 s2; union_of_three_disjoint_sets_cardinality_lemma (difference s1 s2) (intersection s1 s2) (difference s2 s1); cardinality_matches_difference_plus_intersection_lemma s1 s2 let difference_cardinality_lemma () : Lemma (difference_cardinality_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). cardinality (difference s1 s2) + cardinality (difference s2 s1) + cardinality (intersection s1 s2) = cardinality (union s1 s2) /\ cardinality (difference s1 s2) = cardinality s1 - cardinality (intersection s1 s2) with difference_cardinality_helper a s1 s2 let subset_helper (a: eqtype) (s1: set a) (s2: set a) : Lemma (subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2)) = introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) ==> subset s1 s2 with _. introduce forall x. s1 x = true ==> s2 x = true with assert (mem x s1 = s1 x) let subset_lemma () : Lemma (subset_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). subset s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 ==> mem o s2) with subset_helper a s1 s2 let equal_lemma () : Lemma (equal_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). equal s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) with ( introduce (forall o.{:pattern mem o s1 \/ mem o s2} mem o s1 <==> mem o s2) ==> equal s1 s2 with _. introduce forall x. s1 x = true <==> s2 x = true with assert (mem x s1 = s1 x /\ mem x s2 = s2 x) ) let equal_extensionality_lemma () : Lemma (equal_extensionality_fact) = () let disjoint_lemma () : Lemma (disjoint_fact) = introduce forall (a: eqtype) (s1: set a) (s2: set a). disjoint s1 s2 <==> (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) with ( introduce (forall o.{:pattern mem o s1 \/ mem o s2} not (mem o s1) \/ not (mem o s2)) ==> disjoint s1 s2 with _. ( introduce forall x. not (s1 x && s2 x) with assert (not (mem x s1) \/ not (mem x s2)) ) ) let insert_remove_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s) (ensures insert x (remove x s) == s) = assert (feq s (insert x (remove x s))) let insert_remove_lemma () : Lemma (insert_remove_fact) = introduce forall (a: eqtype) (x: a) (s: set a). mem x s = true ==> insert x (remove x s) == s with introduce mem x s = true ==> insert x (remove x s) == s with _. insert_remove_helper a x s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "FStar.FiniteSet.Base.fst" }
[ { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "FLT" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
a: Prims.eqtype -> x: a -> s: FStar.FiniteSet.Base.set a -> FStar.Pervasives.Lemma (requires FStar.FiniteSet.Base.mem x s = false) (ensures FStar.FiniteSet.Base.remove x (FStar.FiniteSet.Base.insert x s) == s)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.FiniteSet.Base.set", "Prims._assert", "FStar.FunctionalExtensionality.feq", "Prims.bool", "FStar.FiniteSet.Base.remove", "FStar.FiniteSet.Base.insert", "Prims.unit", "Prims.b2t", "Prims.op_Equality", "FStar.FiniteSet.Base.mem", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let remove_insert_helper (a: eqtype) (x: a) (s: set a) : Lemma (requires mem x s = false) (ensures remove x (insert x s) == s) =
assert (feq s (remove x (insert x s)))
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.pad_to_128_bits_upper
val pad_to_128_bits_upper (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 8) (ensures (let new_hi = (((hi64 q) / pow2 ((8 - num_bytes) * 8)) * pow2 ((8 - num_bytes) * 8)) % pow2_64 in (let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 new_hi)) in q' == be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes)))))
val pad_to_128_bits_upper (q:quad32) (num_bytes:int) : Lemma (requires 1 <= num_bytes /\ num_bytes < 8) (ensures (let new_hi = (((hi64 q) / pow2 ((8 - num_bytes) * 8)) * pow2 ((8 - num_bytes) * 8)) % pow2_64 in (let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 new_hi)) in q' == be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes)))))
let pad_to_128_bits_upper (q:quad32) (num_bytes:int) = let n = num_bytes in let new_hi = ((hi64 q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in hi64_reveal (); let f (n:nat{1 <= n /\ n < 8}) = (hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == ((hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); assert_norm (f 5); assert_norm (f 6); assert_norm (f 7); assert (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64); let s = be_quad32_to_bytes q in let s' = slice s 0 n in let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 new_hi)) in let s'' = pad_to_128_bits s' in let q'' = be_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in if n < 4 then ( lemma_div_n_8_upper1 q n; lemma_64_32_hi1 q' (hi64 q) new_hi n; lemma_pad_to_32_bits s0_4 s0_4'' n; () ) else ( lemma_div_n_8_upper2 q (n - 4); lemma_64_32_hi2 q' (hi64 q) new_hi (n - 4); lemma_pad_to_32_bits s4_8 s4_8'' (n - 4); () ); lemma_slices_be_quad32_to_bytes q; lemma_slices_be_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 4 ==> equal s4_8'' zero_4); assert (equal s8_12'' zero_4); assert (equal s12_16'' zero_4); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 320, "start_col": 0, "start_line": 269 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) = assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1) = assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_slices_be_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8); be_bytes_to_quad32_reveal (); () let lemma_four_zero (_:unit) : Lemma (ensures four_to_nat 8 (seq_to_four_BE (create 4 0)) == 0) = let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); ()
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> num_bytes: Prims.int -> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 8) (ensures (let new_hi = (Vale.Arch.Types.hi64 q / Prims.pow2 ((8 - num_bytes) * 8)) * Prims.pow2 ((8 - num_bytes) * 8) % Vale.Def.Words_s.pow2_64 in let q' = Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 0) (Vale.Def.Words.Two_s.nat_to_two 32 new_hi) ) in q' == Vale.Def.Types_s.be_bytes_to_quad32 (Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes q) 0 num_bytes))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.int", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat8", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.create", "Vale.AES.GCM_helpers_BE.lemma_four_zero", "Vale.AES.GCM_helpers_BE.lemma_slices_be_bytes_to_quad32", "Vale.AES.Types_helpers.lemma_slices_be_quad32_to_bytes", "Vale.AES.GCM_helpers_BE.lemma_pad_to_32_bits", "Vale.AES.GCM_helpers_BE.lemma_64_32_hi1", "Vale.Arch.Types.hi64", "Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper1", "Prims.bool", "Prims.op_Subtraction", "Vale.AES.GCM_helpers_BE.lemma_64_32_hi2", "Vale.AES.GCM_helpers_BE.lemma_div_n_8_upper2", "FStar.Seq.Base.slice", "Vale.Def.Types_s.be_bytes_to_quad32", "Vale.AES.GCTR_BE_s.pad_to_128_bits", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat32", "Vale.Def.Words.Four_s.two_two_to_four", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mktwo", "Vale.Def.Words_s.two", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words.Seq_s.seq16", "Vale.Arch.Types.be_quad32_to_bytes", "Prims.eq2", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.pow2", "Prims.op_Modulus", "Vale.Def.Words_s.pow2_64", "FStar.Pervasives.assert_norm", "Prims.nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.logical", "Vale.Arch.Types.hi64_def", "Vale.Arch.Types.hi64_reveal" ]
[]
false
false
true
false
false
let pad_to_128_bits_upper (q: quad32) (num_bytes: int) =
let n = num_bytes in let new_hi = ((hi64 q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in hi64_reveal (); let f (n: nat{1 <= n /\ n < 8}) = (hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == ((hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); assert_norm (f 5); assert_norm (f 6); assert_norm (f 7); assert (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64); let s = be_quad32_to_bytes q in let s' = slice s 0 n in let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 new_hi)) in let s'' = pad_to_128_bits s' in let q'' = be_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in if n < 4 then (lemma_div_n_8_upper1 q n; lemma_64_32_hi1 q' (hi64 q) new_hi n; lemma_pad_to_32_bits s0_4 s0_4'' n; ()) else (lemma_div_n_8_upper2 q (n - 4); lemma_64_32_hi2 q' (hi64 q) new_hi (n - 4); lemma_pad_to_32_bits s4_8 s4_8'' (n - 4); ()); lemma_slices_be_quad32_to_bytes q; lemma_slices_be_bytes_to_quad32 s''; lemma_four_zero (); let zero_4:seq nat8 = create 4 0 in assert (n < 4 ==> equal s4_8'' zero_4); assert (equal s8_12'' zero_4); assert (equal s12_16'' zero_4); ()
false
Imp.fst
Imp.eval
val eval : prog -> rval
val eval : prog -> rval
let eval p = let rm = List.Tot.fold_left (fun r i -> eval' i r) (fun _ -> 0) p in rm (R 0)
{ "file_name": "examples/tactics/Imp.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 90, "end_line": 76, "start_col": 0, "start_line": 76 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Imp //#set-options "--debug Imp --debug_level SMTQuery" open FStar.Mul open FStar.Tactics.V2 open FStar.Tactics.CanonCommSemiring open FStar.Algebra.CommMonoid type rval = int type reg = | R of n:nat{n < 10} type regmap = reg -> rval noeq type inst = | Add : reg -> reg -> reg -> inst | Sub : reg -> reg -> reg -> inst | Mul : reg -> reg -> reg -> inst | Const : rval -> reg -> inst //| If0 : reg -> prog -> prog -> inst //| Seq : prog -> inst and prog = list inst module L = FStar.List.Tot let rec size : inst -> pos = function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1 //| If0 _ i j -> 1 + size_l i + size_l j //| Seq i -> 1 + size_l i and size_l : prog -> pos = function | [] -> 1 | hd::tl -> size hd + size_l tl val override : reg -> rval -> regmap -> regmap let override r v rm = fun r' -> if r = r' then v else rm r' let rec eval' (i:inst) (rm:regmap) : Tot regmap (decreases (size i)) = match i with | Add r1 r2 r3 -> override r3 (rm r1 + rm r2) rm | Sub r1 r2 r3 -> override r3 (rm r1 - rm r2) rm | Mul r1 r2 r3 -> override r3 (rm r1 * rm r2) rm | Const v r -> override r v rm //| Seq [] -> rm // | Seq (p::ps) -> eval' (Seq ps) (eval' p rm) // | If0 r p0 p1 -> // if rm r = 0 // then eval' (Seq p0) rm // else eval' (Seq p1) rm (* Run in all zeros and get the 0th reg *) val eval : prog -> rval
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": false, "source_file": "Imp.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Imp.prog -> Imp.rval
Prims.Tot
[ "total" ]
[]
[ "Imp.prog", "Imp.R", "Imp.regmap", "FStar.List.Tot.Base.fold_left", "Imp.inst", "Imp.eval'", "Imp.reg", "Imp.rval" ]
[]
false
false
false
true
false
let eval p =
let rm = List.Tot.fold_left (fun r i -> eval' i r) (fun _ -> 0) p in rm (R 0)
false
Imp.fst
Imp.equiv
val equiv : p1: Imp.prog -> p2: Imp.prog -> Prims.logical
let equiv p1 p2 = eval p1 == eval p2
{ "file_name": "examples/tactics/Imp.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 78, "start_col": 0, "start_line": 78 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Imp //#set-options "--debug Imp --debug_level SMTQuery" open FStar.Mul open FStar.Tactics.V2 open FStar.Tactics.CanonCommSemiring open FStar.Algebra.CommMonoid type rval = int type reg = | R of n:nat{n < 10} type regmap = reg -> rval noeq type inst = | Add : reg -> reg -> reg -> inst | Sub : reg -> reg -> reg -> inst | Mul : reg -> reg -> reg -> inst | Const : rval -> reg -> inst //| If0 : reg -> prog -> prog -> inst //| Seq : prog -> inst and prog = list inst module L = FStar.List.Tot let rec size : inst -> pos = function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1 //| If0 _ i j -> 1 + size_l i + size_l j //| Seq i -> 1 + size_l i and size_l : prog -> pos = function | [] -> 1 | hd::tl -> size hd + size_l tl val override : reg -> rval -> regmap -> regmap let override r v rm = fun r' -> if r = r' then v else rm r' let rec eval' (i:inst) (rm:regmap) : Tot regmap (decreases (size i)) = match i with | Add r1 r2 r3 -> override r3 (rm r1 + rm r2) rm | Sub r1 r2 r3 -> override r3 (rm r1 - rm r2) rm | Mul r1 r2 r3 -> override r3 (rm r1 * rm r2) rm | Const v r -> override r v rm //| Seq [] -> rm // | Seq (p::ps) -> eval' (Seq ps) (eval' p rm) // | If0 r p0 p1 -> // if rm r = 0 // then eval' (Seq p0) rm // else eval' (Seq p1) rm (* Run in all zeros and get the 0th reg *) val eval : prog -> rval //let eval p = let rm = eval' (Seq p) (fun _ -> 0) in rm (R 0) let eval p = let rm = List.Tot.fold_left (fun r i -> eval' i r) (fun _ -> 0) p in rm (R 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": false, "source_file": "Imp.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
p1: Imp.prog -> p2: Imp.prog -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Imp.prog", "Prims.eq2", "Imp.rval", "Imp.eval", "Prims.logical" ]
[]
false
false
false
true
true
let equiv p1 p2 =
eval p1 == eval p2
false
Imp.fst
Imp.mk42
val mk42:prog
val mk42:prog
let mk42 : prog = [ Const 1 (R 0); Add (R 0) (R 0) (R 1); Add (R 1) (R 1) (R 0); Add (R 0) (R 0) (R 1); Add (R 1) (R 1) (R 0); Add (R 0) (R 0) (R 1); Add (R 1) (R 0) (R 0); Const 6 (R 1); Sub (R 0) (R 1) (R 0); ]
{ "file_name": "examples/tactics/Imp.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 90, "start_col": 0, "start_line": 80 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Imp //#set-options "--debug Imp --debug_level SMTQuery" open FStar.Mul open FStar.Tactics.V2 open FStar.Tactics.CanonCommSemiring open FStar.Algebra.CommMonoid type rval = int type reg = | R of n:nat{n < 10} type regmap = reg -> rval noeq type inst = | Add : reg -> reg -> reg -> inst | Sub : reg -> reg -> reg -> inst | Mul : reg -> reg -> reg -> inst | Const : rval -> reg -> inst //| If0 : reg -> prog -> prog -> inst //| Seq : prog -> inst and prog = list inst module L = FStar.List.Tot let rec size : inst -> pos = function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1 //| If0 _ i j -> 1 + size_l i + size_l j //| Seq i -> 1 + size_l i and size_l : prog -> pos = function | [] -> 1 | hd::tl -> size hd + size_l tl val override : reg -> rval -> regmap -> regmap let override r v rm = fun r' -> if r = r' then v else rm r' let rec eval' (i:inst) (rm:regmap) : Tot regmap (decreases (size i)) = match i with | Add r1 r2 r3 -> override r3 (rm r1 + rm r2) rm | Sub r1 r2 r3 -> override r3 (rm r1 - rm r2) rm | Mul r1 r2 r3 -> override r3 (rm r1 * rm r2) rm | Const v r -> override r v rm //| Seq [] -> rm // | Seq (p::ps) -> eval' (Seq ps) (eval' p rm) // | If0 r p0 p1 -> // if rm r = 0 // then eval' (Seq p0) rm // else eval' (Seq p1) rm (* Run in all zeros and get the 0th reg *) val eval : prog -> rval //let eval p = let rm = eval' (Seq p) (fun _ -> 0) in rm (R 0) let eval p = let rm = List.Tot.fold_left (fun r i -> eval' i r) (fun _ -> 0) p in rm (R 0) let equiv p1 p2 = eval p1 == eval p2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": false, "source_file": "Imp.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Imp.prog
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Imp.inst", "Imp.Const", "Imp.R", "Imp.Add", "Imp.Sub", "Prims.Nil" ]
[]
false
false
false
true
false
let mk42:prog =
[ Const 1 (R 0); Add (R 0) (R 0) (R 1); Add (R 1) (R 1) (R 0); Add (R 0) (R 0) (R 1); Add (R 1) (R 1) (R 0); Add (R 0) (R 0) (R 1); Add (R 1) (R 0) (R 0); Const 6 (R 1); Sub (R 0) (R 1) (R 0) ]
false
Vale.AES.GCM_helpers_BE.fst
Vale.AES.GCM_helpers_BE.pad_to_128_bits_lower
val pad_to_128_bits_lower (q:quad32) (num_bytes:int) : Lemma (requires 8 <= num_bytes /\ num_bytes < 16) (ensures (let new_lo = (((lo64 q) / pow2 ((16 - num_bytes) * 8)) * pow2 ((16 - num_bytes) * 8)) % pow2_64 in (let q' = two_two_to_four (Mktwo (nat_to_two 32 new_lo) (nat_to_two 32 (hi64 q))) in q' == be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes)))))
val pad_to_128_bits_lower (q:quad32) (num_bytes:int) : Lemma (requires 8 <= num_bytes /\ num_bytes < 16) (ensures (let new_lo = (((lo64 q) / pow2 ((16 - num_bytes) * 8)) * pow2 ((16 - num_bytes) * 8)) % pow2_64 in (let q' = two_two_to_four (Mktwo (nat_to_two 32 new_lo) (nat_to_two 32 (hi64 q))) in q' == be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes)))))
let pad_to_128_bits_lower (q:quad32) (num_bytes:int) = let n = num_bytes in let new_lo = (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64 in lo64_reveal (); hi64_reveal (); let f (n:nat{8 <= n /\ n < 16}) = (lo64_def q / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8) == ((lo64_def q / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64 in assert_norm (f 8); assert_norm (f 9); assert_norm (f 10); assert_norm (f 11); assert_norm (f 12); assert_norm (f 13); assert_norm (f 14); assert_norm (f 15); assert (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8) == (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64); let s = be_quad32_to_bytes q in let s' = slice s 0 n in let q' = two_two_to_four (Mktwo (nat_to_two 32 new_lo) (nat_to_two 32 (hi64 q))) in let s'' = pad_to_128_bits s' in let q'' = be_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 12 then ( lemma_div_n_8_lower1 q (n - 8); lemma_64_32_lo1 q' (lo64 q) new_lo (n - 8); lemma_pad_to_32_bits s8_12 s8_12'' (n - 8); () ) else ( lemma_div_n_8_lower2 q (n - 12); lemma_64_32_lo2 q' (lo64 q) new_lo (n - 12); lemma_pad_to_32_bits s12_16 s12_16'' (n - 12); () ); lemma_slices_be_quad32_to_bytes q; lemma_slices_be_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 12 ==> equal s12_16'' zero_4); ()
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 379, "start_col": 0, "start_line": 324 }
module Vale.AES.GCM_helpers_BE open FStar.Tactics open Vale.Def.Words_s open Vale.Def.Words.Seq_s open Vale.Def.Types_s open Vale.Arch.Types open FStar.Mul open FStar.Seq open Vale.Def.Opaque_s open Vale.Def.Words.Two_s open Vale.Def.Words.Four_s open Vale.AES.AES_BE_s open Vale.AES.GCTR_BE_s open FStar.Math.Lemmas open Vale.Lib.Seqs open Vale.AES.Types_helpers let no_extra_bytes_helper s num_bytes = () let be_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let final = index s num_blocks in let x = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes in let x' = slice (be_quad32_to_bytes final) 0 num_extra in be_seq_quad32_to_bytes_of_singleton final; assert (be_quad32_to_bytes final == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 final))); assert (equal (create 1 final) (slice s num_blocks (length s))); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s num_blocks (length s)))) 0 num_extra); slice_commutes_be_seq_quad32_to_bytes s num_blocks (length s); assert (x' == slice (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) (length s * 16)) 0 num_extra); assert (x' == slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (num_blocks * 16) num_bytes); assert (equal x' x); () let pad_to_128_bits_multiples (b:seq nat8) : Lemma (let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) = let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in if length b < 16 then ( assert (full_bytes == empty); assert (partial_bytes == b); append_empty_l(pad_to_128_bits partial_bytes); () ) else ( assert (length full_bytes + length partial_bytes == length b); assert (length full_bytes % 16 == 0); let num_extra_bytes = length b % 16 in assert (num_extra_bytes == (length partial_bytes) % 16); if num_extra_bytes = 0 then ( lemma_split b full_blocks; assert (b == full_bytes @| partial_bytes); () ) else ( let pad = create (16 - num_extra_bytes) 0 in assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad))); () ); () ) let pad_to_128_bits_be_quad32_to_bytes (s:seq quad32) (num_bytes:int) = let num_extra = num_bytes % 16 in let num_blocks = num_bytes / 16 in let full_quads,final_quads = split s num_blocks in assert(length final_quads == 1); let final_quad = index final_quads 0 in let b = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes in pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes let full_blocks = (length b) / 16 * 16 in let full_bytes, partial_bytes = split b full_blocks in slice_commutes_be_seq_quad32_to_bytes0 s num_blocks; slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes 0 full_blocks; assert (full_bytes == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE full_quads)); slice_slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes full_blocks num_bytes; be_seq_quad32_to_bytes_tail_prefix s num_bytes; () #reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1" let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 2 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = assert (n == 0 \/ n == 1 \/ n == 2); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (2 * 8) == 0x10000); assert_norm (pow2 (3 * 8) == 0x1000000); assert_norm (pow2 (4 * 8) == 0x100000000); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 0 ==> x / pow2 (8 * (4 - n)) == x / 0x100000000); assert (n == 1 ==> x / pow2 (8 * (4 - n)) == x / 0x1000000); assert (n == 2 ==> x / pow2 (8 * (4 - n)) == x / 0x10000); assert_norm (((x / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2 (8 * 4) == 0); assert_norm (((x / pow2 (8 * 3)) * pow2 (8 * 3)) % pow2 (8 * 3) == 0); assert_norm (((x / pow2 (8 * 2)) * pow2 (8 * 2)) % pow2 (8 * 2) == 0); () let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma (requires n <= 4 /\ (forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==> index s'' i == (if i < n then index s i else 0)) ) (ensures four_to_nat 8 (seq_to_four_BE s'') == (four_to_nat 8 (seq_to_four_BE s) / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4); assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); assert_norm (four_to_nat 8 (seq_to_four_BE s'') == four_to_nat_unfold 8 (seq_to_four_BE s'')); assert_norm (pow2 (0 * 8) == 1); assert_norm (pow2 (1 * 8) == 0x100); let x = four_to_nat 8 (seq_to_four_BE s'') in assert (n == 3 ==> x / pow2 (8 * (4 - n)) == x / 0x100); assert (n == 4 ==> x / pow2 (8 * (4 - n)) == x / 0x1); assert_norm (((x / pow2 (8 * 1)) * pow2 (8 * 1)) % pow2 (8 * 1) == 0); assert_norm (((x / pow2 (8 * 0)) * pow2 (8 * 0)) % pow2 (8 * 0) == 0); () let lemma_div_n_8_upper1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((hi64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = ((hi64_def q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.hi3 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 0); assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); () let lemma_div_n_8_upper2_helper (q:quad32) (n:nat) : Lemma (requires n <= 2) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 2); assert_norm (f 1); assert_norm (f 0); () let lemma_div_n_8_upper2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (hi64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); if n <= 2 then lemma_div_n_8_upper2_helper q n else let Mkfour _ _ _ _ = q in // avoid ifuel let f (n:nat{n <= 4}) = (hi64_def q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.hi3 + (q.hi2 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) in assert_norm (f 4); assert_norm (f 3); () let lemma_div_n_8_lower1 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures ((lo64 q / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32 == (q.lo1 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper1 (Mkfour 0 0 q0 q1) n let lemma_div_n_8_lower2 (q:quad32) (n:nat) : Lemma (requires n <= 4) (ensures (lo64 q / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) == 0x100000000 * q.lo1 + (q.lo0 / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n))) = hi64_reveal (); lo64_reveal (); let Mkfour q0 q1 _ _ = q in lemma_div_n_8_upper2 (Mkfour 0 0 q0 q1) n let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' % pow2_32 == 0 /\ hi' / pow2_32 == q'.hi3 /\ q' == Mkfour 0 0 0 q'.hi3) = assert_norm (((hi / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((hi / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm ((((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32) % pow2_32 == ((hi / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma (requires n <= 4 /\ hi' == (hi / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 0) (nat_to_two 32 hi') ) (ensures hi' == 0x100000000 * q'.hi3 + q'.hi2 /\ q' == Mkfour 0 0 q'.hi2 q'.hi3) = assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi'); assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0); () let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' % pow2_32 == 0 /\ lo' / pow2_32 == q'.lo1 /\ q'.lo0 == 0) = assert_norm (((lo / pow2 (8 * 4)) * pow2 (8 * 4)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 5)) * pow2 (8 * 5)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 6)) * pow2 (8 * 6)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 7)) * pow2 (8 * 7)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * 8)) * pow2 (8 * 8)) % pow2_32 == 0); assert_norm (((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n)) / pow2_32) % pow2_32 == ((lo / pow2 (8 * (8 - n))) * pow2 (8 * (8 - n))) / pow2_32); assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma (requires n <= 4 /\ lo' == (lo / pow2 (8 * (4 - n))) * pow2 (8 * (4 - n)) /\ four_to_two_two q' == Mktwo (nat_to_two 32 lo') (Mktwo q'.hi2 q'.hi3) ) (ensures lo' == q'.lo0 + 0x100000000 * q'.lo1) = assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo'); () let lemma_slices_be_bytes_to_quad32 (s:seq16 nat8) : Lemma (ensures ( let q = be_bytes_to_quad32 s in q.hi3 == four_to_nat 8 (seq_to_four_BE (slice s 0 4)) /\ q.hi2 == four_to_nat 8 (seq_to_four_BE (slice s 4 8)) /\ q.lo1 == four_to_nat 8 (seq_to_four_BE (slice s 8 12)) /\ q.lo0 == four_to_nat 8 (seq_to_four_BE (slice s 12 16)) )) = reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8); be_bytes_to_quad32_reveal (); () let lemma_four_zero (_:unit) : Lemma (ensures four_to_nat 8 (seq_to_four_BE (create 4 0)) == 0) = let s = create 4 0 in assert_norm (four_to_nat 8 (seq_to_four_BE s) == four_to_nat_unfold 8 (seq_to_four_BE s)); () let pad_to_128_bits_upper (q:quad32) (num_bytes:int) = let n = num_bytes in let new_hi = ((hi64 q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in hi64_reveal (); let f (n:nat{1 <= n /\ n < 8}) = (hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == ((hi64_def q / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64 in assert_norm (f 1); assert_norm (f 2); assert_norm (f 3); assert_norm (f 4); assert_norm (f 5); assert_norm (f 6); assert_norm (f 7); assert (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8) == (((hi64 q) / pow2 ((8 - n) * 8)) * pow2 ((8 - n) * 8)) % pow2_64); let s = be_quad32_to_bytes q in let s' = slice s 0 n in let q' = two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 new_hi)) in let s'' = pad_to_128_bits s' in let q'' = be_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in if n < 4 then ( lemma_div_n_8_upper1 q n; lemma_64_32_hi1 q' (hi64 q) new_hi n; lemma_pad_to_32_bits s0_4 s0_4'' n; () ) else ( lemma_div_n_8_upper2 q (n - 4); lemma_64_32_hi2 q' (hi64 q) new_hi (n - 4); lemma_pad_to_32_bits s4_8 s4_8'' (n - 4); () ); lemma_slices_be_quad32_to_bytes q; lemma_slices_be_bytes_to_quad32 s''; lemma_four_zero (); let zero_4 : seq nat8 = create 4 0 in assert (n < 4 ==> equal s4_8'' zero_4); assert (equal s8_12'' zero_4); assert (equal s12_16'' zero_4); () #reset-options "--smtencoding.elim_box true --z3rlimit 100 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
{ "checked_file": "/", "dependencies": [ "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Two_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.Types_helpers.fsti.checked", "Vale.AES.GCTR_BE_s.fst.checked", "Vale.AES.AES_BE_s.fst.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM_helpers_BE.fst" }
[ { "abbrev": false, "full_module": "Vale.AES.Types_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_BE_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_BE_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Two_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Seq_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "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": true, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> num_bytes: Prims.int -> FStar.Pervasives.Lemma (requires 8 <= num_bytes /\ num_bytes < 16) (ensures (let new_lo = (Vale.Arch.Types.lo64 q / Prims.pow2 ((16 - num_bytes) * 8)) * Prims.pow2 ((16 - num_bytes) * 8) % Vale.Def.Words_s.pow2_64 in let q' = Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 new_lo) (Vale.Def.Words.Two_s.nat_to_two 32 (Vale.Arch.Types.hi64 q))) in q' == Vale.Def.Types_s.be_bytes_to_quad32 (Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes q) 0 num_bytes))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.int", "Vale.Def.Types_s.nat32", "Prims.unit", "Prims._assert", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "FStar.Seq.Base.create", "Vale.AES.GCM_helpers_BE.lemma_four_zero", "Vale.AES.GCM_helpers_BE.lemma_slices_be_bytes_to_quad32", "Vale.AES.Types_helpers.lemma_slices_be_quad32_to_bytes", "Vale.AES.GCM_helpers_BE.lemma_pad_to_32_bits", "Prims.op_Subtraction", "Vale.AES.GCM_helpers_BE.lemma_64_32_lo1", "Vale.Arch.Types.lo64", "Vale.AES.GCM_helpers_BE.lemma_div_n_8_lower1", "Prims.bool", "Vale.AES.GCM_helpers_BE.lemma_64_32_lo2", "Vale.AES.GCM_helpers_BE.lemma_div_n_8_lower2", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat32", "FStar.Seq.Base.slice", "Vale.Def.Types_s.be_bytes_to_quad32", "Vale.AES.GCTR_BE_s.pad_to_128_bits", "Vale.Def.Words.Four_s.two_two_to_four", "Vale.Def.Words_s.Mktwo", "Vale.Def.Words_s.two", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Arch.Types.hi64", "Vale.Def.Words.Seq_s.seq16", "Vale.Arch.Types.be_quad32_to_bytes", "Prims.eq2", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.pow2", "Prims.op_Modulus", "Vale.Def.Words_s.pow2_64", "FStar.Pervasives.assert_norm", "Prims.nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.logical", "Vale.Arch.Types.lo64_def", "Vale.Arch.Types.hi64_reveal", "Vale.Arch.Types.lo64_reveal" ]
[]
false
false
true
false
false
let pad_to_128_bits_lower (q: quad32) (num_bytes: int) =
let n = num_bytes in let new_lo = (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64 in lo64_reveal (); hi64_reveal (); let f (n: nat{8 <= n /\ n < 16}) = (lo64_def q / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8) == ((lo64_def q / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64 in assert_norm (f 8); assert_norm (f 9); assert_norm (f 10); assert_norm (f 11); assert_norm (f 12); assert_norm (f 13); assert_norm (f 14); assert_norm (f 15); assert (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8) == (((lo64 q) / pow2 ((16 - n) * 8)) * pow2 ((16 - n) * 8)) % pow2_64); let s = be_quad32_to_bytes q in let s' = slice s 0 n in let q' = two_two_to_four (Mktwo (nat_to_two 32 new_lo) (nat_to_two 32 (hi64 q))) in let s'' = pad_to_128_bits s' in let q'' = be_bytes_to_quad32 s'' in let s0_4 = slice s 0 4 in let s4_8 = slice s 4 8 in let s8_12 = slice s 8 12 in let s12_16 = slice s 12 16 in let s0_4'' = slice s'' 0 4 in let s4_8'' = slice s'' 4 8 in let s8_12'' = slice s'' 8 12 in let s12_16'' = slice s'' 12 16 in let Mkfour q0 q1 q2 q3 = q in let Mkfour q0' q1' q2' q3' = q' in let Mkfour q0'' q1'' q2'' q3'' = q'' in if n < 12 then (lemma_div_n_8_lower1 q (n - 8); lemma_64_32_lo1 q' (lo64 q) new_lo (n - 8); lemma_pad_to_32_bits s8_12 s8_12'' (n - 8); ()) else (lemma_div_n_8_lower2 q (n - 12); lemma_64_32_lo2 q' (lo64 q) new_lo (n - 12); lemma_pad_to_32_bits s12_16 s12_16'' (n - 12); ()); lemma_slices_be_quad32_to_bytes q; lemma_slices_be_bytes_to_quad32 s''; lemma_four_zero (); let zero_4:seq nat8 = create 4 0 in assert (n < 12 ==> equal s12_16'' zero_4); ()
false
Imp.fst
Imp.override
val override : reg -> rval -> regmap -> regmap
val override : reg -> rval -> regmap -> regmap
let override r v rm = fun r' -> if r = r' then v else rm r'
{ "file_name": "examples/tactics/Imp.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 57, "start_col": 0, "start_line": 53 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Imp //#set-options "--debug Imp --debug_level SMTQuery" open FStar.Mul open FStar.Tactics.V2 open FStar.Tactics.CanonCommSemiring open FStar.Algebra.CommMonoid type rval = int type reg = | R of n:nat{n < 10} type regmap = reg -> rval noeq type inst = | Add : reg -> reg -> reg -> inst | Sub : reg -> reg -> reg -> inst | Mul : reg -> reg -> reg -> inst | Const : rval -> reg -> inst //| If0 : reg -> prog -> prog -> inst //| Seq : prog -> inst and prog = list inst module L = FStar.List.Tot let rec size : inst -> pos = function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1 //| If0 _ i j -> 1 + size_l i + size_l j //| Seq i -> 1 + size_l i and size_l : prog -> pos = function | [] -> 1 | hd::tl -> size hd + size_l tl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": false, "source_file": "Imp.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Imp.reg -> v: Imp.rval -> rm: Imp.regmap -> Imp.regmap
Prims.Tot
[ "total" ]
[]
[ "Imp.reg", "Imp.rval", "Imp.regmap", "Prims.op_Equality", "Prims.bool" ]
[]
false
false
false
true
false
let override r v rm =
fun r' -> if r = r' then v else rm r'
false
Imp.fst
Imp.size
val size: inst -> pos
val size: inst -> pos
let rec size : inst -> pos = function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1 //| If0 _ i j -> 1 + size_l i + size_l j //| Seq i -> 1 + size_l i and size_l : prog -> pos = function | [] -> 1 | hd::tl -> size hd + size_l tl
{ "file_name": "examples/tactics/Imp.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 51, "start_col": 0, "start_line": 41 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Imp //#set-options "--debug Imp --debug_level SMTQuery" open FStar.Mul open FStar.Tactics.V2 open FStar.Tactics.CanonCommSemiring open FStar.Algebra.CommMonoid type rval = int type reg = | R of n:nat{n < 10} type regmap = reg -> rval noeq type inst = | Add : reg -> reg -> reg -> inst | Sub : reg -> reg -> reg -> inst | Mul : reg -> reg -> reg -> inst | Const : rval -> reg -> inst //| If0 : reg -> prog -> prog -> inst //| Seq : prog -> inst and prog = list inst module L = FStar.List.Tot
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": false, "source_file": "Imp.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
_: Imp.inst -> Prims.pos
Prims.Tot
[ "total" ]
[ "size", "size_l" ]
[ "Imp.inst", "Imp.reg", "Imp.rval", "Prims.pos" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec size: inst -> pos =
function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1
false
Imp.fst
Imp.size_l
val size_l: prog -> pos
val size_l: prog -> pos
let rec size : inst -> pos = function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1 //| If0 _ i j -> 1 + size_l i + size_l j //| Seq i -> 1 + size_l i and size_l : prog -> pos = function | [] -> 1 | hd::tl -> size hd + size_l tl
{ "file_name": "examples/tactics/Imp.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 51, "start_col": 0, "start_line": 41 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Imp //#set-options "--debug Imp --debug_level SMTQuery" open FStar.Mul open FStar.Tactics.V2 open FStar.Tactics.CanonCommSemiring open FStar.Algebra.CommMonoid type rval = int type reg = | R of n:nat{n < 10} type regmap = reg -> rval noeq type inst = | Add : reg -> reg -> reg -> inst | Sub : reg -> reg -> reg -> inst | Mul : reg -> reg -> reg -> inst | Const : rval -> reg -> inst //| If0 : reg -> prog -> prog -> inst //| Seq : prog -> inst and prog = list inst module L = FStar.List.Tot
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": false, "source_file": "Imp.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
_: Imp.prog -> Prims.pos
Prims.Tot
[ "total" ]
[ "size", "size_l" ]
[ "Imp.prog", "Imp.inst", "Prims.list", "Prims.op_Addition", "Imp.size", "Imp.size_l", "Prims.pos" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec size_l: prog -> pos =
function | [] -> 1 | hd :: tl -> size hd + size_l tl
false
Imp.fst
Imp.eval'
val eval' (i: inst) (rm: regmap) : Tot regmap (decreases (size i))
val eval' (i: inst) (rm: regmap) : Tot regmap (decreases (size i))
let rec eval' (i:inst) (rm:regmap) : Tot regmap (decreases (size i)) = match i with | Add r1 r2 r3 -> override r3 (rm r1 + rm r2) rm | Sub r1 r2 r3 -> override r3 (rm r1 - rm r2) rm | Mul r1 r2 r3 -> override r3 (rm r1 * rm r2) rm | Const v r -> override r v rm
{ "file_name": "examples/tactics/Imp.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 65, "start_col": 0, "start_line": 59 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Imp //#set-options "--debug Imp --debug_level SMTQuery" open FStar.Mul open FStar.Tactics.V2 open FStar.Tactics.CanonCommSemiring open FStar.Algebra.CommMonoid type rval = int type reg = | R of n:nat{n < 10} type regmap = reg -> rval noeq type inst = | Add : reg -> reg -> reg -> inst | Sub : reg -> reg -> reg -> inst | Mul : reg -> reg -> reg -> inst | Const : rval -> reg -> inst //| If0 : reg -> prog -> prog -> inst //| Seq : prog -> inst and prog = list inst module L = FStar.List.Tot let rec size : inst -> pos = function | Add _ _ _ | Sub _ _ _ | Mul _ _ _ | Const _ _ -> 1 //| If0 _ i j -> 1 + size_l i + size_l j //| Seq i -> 1 + size_l i and size_l : prog -> pos = function | [] -> 1 | hd::tl -> size hd + size_l tl val override : reg -> rval -> regmap -> regmap let override r v rm = fun r' -> if r = r' then v else rm r'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": false, "source_file": "Imp.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "FStar.Algebra.CommMonoid", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.CanonCommSemiring", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
i: Imp.inst -> rm: Imp.regmap -> Prims.Tot Imp.regmap
Prims.Tot
[ "total", "" ]
[]
[ "Imp.inst", "Imp.regmap", "Imp.reg", "Imp.override", "Prims.op_Addition", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Imp.rval" ]
[ "recursion" ]
false
false
false
true
false
let rec eval' (i: inst) (rm: regmap) : Tot regmap (decreases (size i)) =
match i with | Add r1 r2 r3 -> override r3 (rm r1 + rm r2) rm | Sub r1 r2 r3 -> override r3 (rm r1 - rm r2) rm | Mul r1 r2 r3 -> override r3 (rm r1 * rm r2) rm | Const v r -> override r v rm
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.state
val state : Prims.eqtype
let state = int
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 22, "start_col": 0, "start_line": 22 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "Prims.int" ]
[]
false
false
false
true
false
let state =
int
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.repr
val repr : a: Type -> wp_a: (_: Prims.int -> _: (_: (a * Prims.int) -> Type0) -> Type0) -> Type
let repr = STINT?.repr
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 33, "start_col": 0, "start_line": 33 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
a: Type -> wp_a: (_: Prims.int -> _: (_: (a * Prims.int) -> Type0) -> Type0) -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.IntST._dm4f_STINT_repr" ]
[]
false
false
false
true
true
let repr =
STINT?.repr
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.post
val post : a: Type -> Type
let post = STINT?.post
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 34, "start_col": 0, "start_line": 34 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.IntST._dm4f_STINT_post" ]
[]
false
false
false
true
true
let post =
STINT?.post
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.pre
val pre : Type
let pre = STINT?.pre
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 35, "start_col": 0, "start_line": 35 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.IntST._dm4f_STINT_pre" ]
[]
false
false
false
true
true
let pre =
STINT?.pre
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.wp
val wp : a: Type -> Type
let wp = STINT?.wp
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 36, "start_col": 0, "start_line": 36 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.IntST._dm4f_STINT_wp" ]
[]
false
false
false
true
true
let wp =
STINT?.wp
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.lift_pure_stint
val lift_pure_stint : a: Type -> wp: Prims.pure_wp a -> n: Prims.int -> p: FStar.DM4F.IntST.post a -> Prims.pure_pre
let lift_pure_stint (a:Type) (wp:pure_wp a) (n:int) (p:post a) = wp (fun a -> p (a, n))
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 44, "start_col": 7, "start_line": 43 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post let pre = STINT?.pre let wp = STINT?.wp let get = STINT?.get let put = STINT?.put // We define a lift between PURE and STINT // -- this is analogous to the return for the monad
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
a: Type -> wp: Prims.pure_wp a -> n: Prims.int -> p: FStar.DM4F.IntST.post a -> Prims.pure_pre
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "Prims.int", "FStar.DM4F.IntST.post", "Prims.l_True", "FStar.Pervasives.Native.Mktuple2", "Prims.pure_pre" ]
[]
false
false
false
true
false
let lift_pure_stint (a: Type) (wp: pure_wp a) (n: int) (p: post a) =
wp (fun a -> p (a, n))
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.get'
val get' : unit -> STINT int (fun z post -> post (z, z))
val get' : unit -> STINT int (fun z post -> post (z, z))
let get' () = STINT?.reflect (action_get ())
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 105, "start_col": 0, "start_line": 105 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post let pre = STINT?.pre let wp = STINT?.wp let get = STINT?.get let put = STINT?.put // We define a lift between PURE and STINT // -- this is analogous to the return for the monad // -- but automatically wiring the return here is not done yet unfold let lift_pure_stint (a:Type) (wp:pure_wp a) (n:int) (p:post a) = wp (fun a -> p (a, n)) sub_effect PURE ~> STINT = lift_pure_stint // We define an effect abbreviation for using pre-post conditions effect StInt (a:Type) (pre: pre) (post: (int -> a -> int -> GTot Type0)) = STINT a (fun n0 p -> pre n0 /\ (forall a n1. pre n0 /\ post n0 a n1 ==> p (a, n1))) // Another effect abbreviation for the trivial pre-post conditions effect StNull (a:Type) = STINT a (fun (n0:int) (p:(a * int) -> Type0) -> forall (x:(a * int)). p x) // We define an increment function that we verify intrinsically val incr_intrinsic : unit -> StInt unit (requires (fun n -> True)) (ensures (fun n0 _ n1 -> n1 = n0 + 1)) let incr_intrinsic u = let n = STINT?.get () in STINT?.put (n + 1) // Here is a weaker specification for increment val incr_intrinsic' : unit -> STINT unit (fun s0 post -> forall (s1:int). (s1 > s0) ==> post ((), s1)) let incr_intrinsic' u = let n = STINT?.get () in STINT?.put (n + 1) // Or, we can give increment the weakest possible spec and prove // properties extrinsically (after the fact) using reification val incr : unit -> StNull unit let incr u = let n = STINT?.get() in STINT?.put (n + 1) let incr_increases (s0:int) = assert (snd (reify (incr ()) s0) = s0 + 1) (* Using this extrinsic style we can also prove information-flow control properties of increment and decrement *) let decr () : StNull unit = let n = STINT?.get () in STINT?.put (n - 1) let ifc (h:bool) : StNull int = if h then (incr(); let y = STINT?.get() in decr(); y) else STINT?.get() + 1 let ni_ifc = assert (forall h0 h1 s0. reify (ifc h0) s0 = reify (ifc h1) s0) (* Although we have STINT?.get and STINT?.put now as actions, *) (* we can also "rederive" them using reflection *) val action_get: (u:unit) -> repr int (fun n post -> post (n, n)) let action_get () i = (i, i) val action_put: x:int -> repr unit (fun n post -> post ((), x)) let action_put x i = ((), x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
_: Prims.unit -> FStar.DM4F.IntST.STINT Prims.int
FStar.DM4F.IntST.STINT
[]
[]
[ "Prims.unit", "FStar.DM4F.IntST.action_get", "Prims.int", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
true
false
false
false
let get' () =
STINT?.reflect (action_get ())
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.put'
val put': x:int -> STINT unit (fun z post -> post ((), x))
val put': x:int -> STINT unit (fun z post -> post ((), x))
let put' x = STINT?.reflect (action_put x)
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 108, "start_col": 0, "start_line": 108 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post let pre = STINT?.pre let wp = STINT?.wp let get = STINT?.get let put = STINT?.put // We define a lift between PURE and STINT // -- this is analogous to the return for the monad // -- but automatically wiring the return here is not done yet unfold let lift_pure_stint (a:Type) (wp:pure_wp a) (n:int) (p:post a) = wp (fun a -> p (a, n)) sub_effect PURE ~> STINT = lift_pure_stint // We define an effect abbreviation for using pre-post conditions effect StInt (a:Type) (pre: pre) (post: (int -> a -> int -> GTot Type0)) = STINT a (fun n0 p -> pre n0 /\ (forall a n1. pre n0 /\ post n0 a n1 ==> p (a, n1))) // Another effect abbreviation for the trivial pre-post conditions effect StNull (a:Type) = STINT a (fun (n0:int) (p:(a * int) -> Type0) -> forall (x:(a * int)). p x) // We define an increment function that we verify intrinsically val incr_intrinsic : unit -> StInt unit (requires (fun n -> True)) (ensures (fun n0 _ n1 -> n1 = n0 + 1)) let incr_intrinsic u = let n = STINT?.get () in STINT?.put (n + 1) // Here is a weaker specification for increment val incr_intrinsic' : unit -> STINT unit (fun s0 post -> forall (s1:int). (s1 > s0) ==> post ((), s1)) let incr_intrinsic' u = let n = STINT?.get () in STINT?.put (n + 1) // Or, we can give increment the weakest possible spec and prove // properties extrinsically (after the fact) using reification val incr : unit -> StNull unit let incr u = let n = STINT?.get() in STINT?.put (n + 1) let incr_increases (s0:int) = assert (snd (reify (incr ()) s0) = s0 + 1) (* Using this extrinsic style we can also prove information-flow control properties of increment and decrement *) let decr () : StNull unit = let n = STINT?.get () in STINT?.put (n - 1) let ifc (h:bool) : StNull int = if h then (incr(); let y = STINT?.get() in decr(); y) else STINT?.get() + 1 let ni_ifc = assert (forall h0 h1 s0. reify (ifc h0) s0 = reify (ifc h1) s0) (* Although we have STINT?.get and STINT?.put now as actions, *) (* we can also "rederive" them using reflection *) val action_get: (u:unit) -> repr int (fun n post -> post (n, n)) let action_get () i = (i, i) val action_put: x:int -> repr unit (fun n post -> post ((), x)) let action_put x i = ((), x) val get' : unit -> STINT int (fun z post -> post (z, z)) let get' () = STINT?.reflect (action_get ())
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> FStar.DM4F.IntST.STINT Prims.unit
FStar.DM4F.IntST.STINT
[]
[]
[ "Prims.int", "FStar.DM4F.IntST.action_put", "Prims.unit", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2" ]
[]
false
true
false
false
false
let put' x =
STINT?.reflect (action_put x)
false
OWGCounter.fst
OWGCounter.incr_ghost_contrib
val incr_ghost_contrib (#v1 #v2: G.erased int) (r: ghost_ref int) : Steel unit ((ghost_pts_to r half_perm v1) `star` (ghost_pts_to r half_perm v2)) (fun _ -> (ghost_pts_to r half_perm (v1 + 1)) `star` (ghost_pts_to r half_perm (v2 + 1))) (fun _ -> True) (fun _ _ _ -> v1 == v2)
val incr_ghost_contrib (#v1 #v2: G.erased int) (r: ghost_ref int) : Steel unit ((ghost_pts_to r half_perm v1) `star` (ghost_pts_to r half_perm v2)) (fun _ -> (ghost_pts_to r half_perm (v1 + 1)) `star` (ghost_pts_to r half_perm (v2 + 1))) (fun _ -> True) (fun _ _ _ -> v1 == v2)
let incr_ghost_contrib (#v1 #v2:G.erased int) (r:ghost_ref int) : Steel unit (ghost_pts_to r half_perm v1 `star` ghost_pts_to r half_perm v2) (fun _ -> ghost_pts_to r half_perm (v1+1) `star` ghost_pts_to r half_perm (v2+1)) (fun _ -> True) (fun _ _ _ -> v1 == v2) = ghost_gather_pt #_ #_ #half_perm #half_perm #v1 #v2 r; rewrite_perm r (sum_perm half_perm half_perm) full_perm; ghost_write_pt r (v1+1); ghost_share_pt r; rewrite_slprop (ghost_pts_to r (P.half_perm P.full_perm) (v1+1) `star` ghost_pts_to r (P.half_perm P.full_perm) (v1+1)) (ghost_pts_to r half_perm (v1+1) `star` ghost_pts_to r half_perm (v2+1)) (fun _ -> ())
{ "file_name": "share/steel/examples/steel/OWGCounter.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 215, "start_col": 0, "start_line": 199 }
(* 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. *) (* * An implementation of the parallel counter presented by Owicki and Gries * "Verifying properties of parallel programs: An axiomatic approach.", CACM'76 * * In this example, the main thread forks two worker thread that both * increment a shared counter. The goal of the example is to show that * after both the worker threads are done, the value of the counter is * its original value + 2. * * See http://pm.inf.ethz.ch/publications/getpdf.php for an implementation * of the OWG counters in the Chalice framework. *) module OWGCounter module G = FStar.Ghost open Steel.Memory open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock open Steel.Effect.Atomic open Steel.Effect module R = Steel.Reference module P = Steel.FractionalPermission module A = Steel.Effect.Atomic #set-options "--ide_id_info_off --using_facts_from '* -FStar.Tactics -FStar.Reflection' --fuel 0 --ifuel 0" let half_perm = half_perm full_perm (* Some basic wrappers to avoid issues with normalization. TODO: The frame inference tactic should not normalize fst and snd*) noextract let fst = fst noextract let snd = snd /// The core invariant of the Owicki-Gries counter, shared by the two parties. /// The concrete counter [r] is shared, and the full permission is stored in the invariant. /// Each party also has half permission to their own ghost counter [r1] or [r2], ensuring that /// only them can modify it by retrieving the other half of the permission when accessing the invariant. /// The `__reduce__` attribute indicates the frame inference tactic to unfold this predicate for frame inference only [@@ __reduce__] let lock_inv_slprop (r:ref int) (r1 r2:ghost_ref int) (w:int & int) = ghost_pts_to r1 half_perm (fst w) `star` ghost_pts_to r2 half_perm (snd w) `star` pts_to r full_perm (fst w + snd w) [@@ __reduce__] let lock_inv_pred (r:ref int) (r1 r2:ghost_ref int) = fun (x:int & int) -> lock_inv_slprop r r1 r2 x /// The actual invariant, existentially quantifying over the values currently stored in the two ghost references [@@ __reduce__] let lock_inv (r:ref int) (r1 r2:ghost_ref int) : vprop = h_exists (lock_inv_pred r r1 r2) #push-options "--warn_error -271 --fuel 1 --ifuel 1" /// A helper lemma to reason about the lock invariant let lock_inv_equiv_lemma (r:ref int) (r1 r2:ghost_ref int) : Lemma (lock_inv r r1 r2 `equiv` lock_inv r r2 r1) = let aux (r:ref int) (r1 r2:ghost_ref int) (m:mem) : Lemma (requires interp (hp_of (lock_inv r r1 r2)) m) (ensures interp (hp_of (lock_inv r r2 r1)) m) [SMTPat ()] = assert ( Steel.Memory.h_exists #(int & int) (fun x -> hp_of (lock_inv_pred r r1 r2 x)) == h_exists_sl #(int & int) (lock_inv_pred r r1 r2)) by (FStar.Tactics.norm [delta_only [`%h_exists_sl]]); let w : G.erased (int & int) = id_elim_exists (fun x -> hp_of (lock_inv_pred r r1 r2 x)) m in assert ((ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))) `equiv` (ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w)))) by (FStar.Tactics.norm [delta_attr [`%__steel_reduce__]]; canon' false (`true_p) (`true_p)); reveal_equiv (ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))) (ghost_pts_to r2 half_perm (fst (snd w, fst w)) `star` ghost_pts_to r1 half_perm (snd (snd w, fst w)) `star` pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w))); assert (interp (hp_of (lock_inv_pred r r2 r1 (snd w, fst w))) m); intro_h_exists (snd w, fst w) (fun x -> hp_of (lock_inv_pred r r2 r1 x)) m; assert (interp (Steel.Memory.h_exists (fun x -> hp_of (lock_inv_pred r r2 r1 x))) m); assert ( Steel.Memory.h_exists #(int & int) (fun x -> hp_of (lock_inv_pred r r2 r1 x)) == h_exists_sl #(int & int) (lock_inv_pred r r2 r1)) by (FStar.Tactics.norm [delta_only [`%h_exists_sl]]) in reveal_equiv (lock_inv r r1 r2) (lock_inv r r2 r1) #pop-options /// Acquiring the shared lock invariant inline_for_extraction noextract let og_acquire (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) : SteelT unit emp (fun _ -> lock_inv r r_mine r_other) = acquire l; if b then begin rewrite_slprop (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (lock_inv r r_mine r_other) (fun _ -> ()); () end else begin rewrite_slprop (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (lock_inv r r_other r_mine) (fun _ -> ()); lock_inv_equiv_lemma r r_other r_mine; rewrite_slprop (lock_inv r r_other r_mine) (lock_inv r r_mine r_other) (fun _ -> reveal_equiv (lock_inv r r_other r_mine) (lock_inv r r_mine r_other)) end /// Releasing the shared lock invariant inline_for_extraction noextract let og_release (r:ref int) (r_mine r_other:ghost_ref int) (b:G.erased bool) (l:lock (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine))) : SteelT unit (lock_inv r r_mine r_other) (fun _ -> emp) = if b then begin rewrite_slprop (lock_inv r r_mine r_other) (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (fun _ -> ()); () end else begin lock_inv_equiv_lemma r r_mine r_other; rewrite_slprop (lock_inv r r_mine r_other) (lock_inv r r_other r_mine) (fun _ -> reveal_equiv (lock_inv r r_mine r_other) (lock_inv r r_other r_mine)); rewrite_slprop (lock_inv r r_other r_mine) (lock_inv r (if b then r_mine else r_other) (if b then r_other else r_mine)) (fun _ -> ()) end; release l inline_for_extraction noextract let incr_ctr (#v:G.erased int) (r:ref int) : SteelT unit (pts_to r full_perm v) (fun _ -> pts_to r full_perm (v+1)) = let n = R.read_pt r in R.write_pt r (n+1); rewrite_slprop (pts_to r full_perm (n + 1)) (pts_to r full_perm (v+1)) (fun _ -> ()) inline_for_extraction noextract let rewrite_perm(#a:Type) (#v:G.erased a) (r:ghost_ref a) (p1 p2:P.perm) : Steel unit (ghost_pts_to r p1 v) (fun _ -> ghost_pts_to r p2 v) (fun _ -> p1 == p2) (fun _ _ _ -> True) = rewrite_slprop (ghost_pts_to r p1 v) (ghost_pts_to r p2 v) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "OWGCounter.fst" }
[ { "abbrev": true, "full_module": "Steel.Effect.Atomic", "short_module": "A" }, { "abbrev": true, "full_module": "Steel.FractionalPermission", "short_module": "P" }, { "abbrev": true, "full_module": "Steel.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.Reference.ghost_ref Prims.int -> Steel.Effect.Steel Prims.unit
Steel.Effect.Steel
[]
[]
[ "FStar.Ghost.erased", "Prims.int", "Steel.Reference.ghost_ref", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.Reference.ghost_pts_to", "Steel.FractionalPermission.half_perm", "Steel.FractionalPermission.full_perm", "Prims.op_Addition", "FStar.Ghost.reveal", "OWGCounter.half_perm", "Steel.Memory.mem", "Prims.unit", "Steel.Reference.ghost_share_pt", "Steel.Reference.ghost_write_pt", "OWGCounter.rewrite_perm", "Steel.FractionalPermission.sum_perm", "Steel.Reference.ghost_gather_pt", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True", "Prims.eq2" ]
[]
false
true
false
false
false
let incr_ghost_contrib (#v1 #v2: G.erased int) (r: ghost_ref int) : Steel unit ((ghost_pts_to r half_perm v1) `star` (ghost_pts_to r half_perm v2)) (fun _ -> (ghost_pts_to r half_perm (v1 + 1)) `star` (ghost_pts_to r half_perm (v2 + 1))) (fun _ -> True) (fun _ _ _ -> v1 == v2) =
ghost_gather_pt #_ #_ #half_perm #half_perm #v1 #v2 r; rewrite_perm r (sum_perm half_perm half_perm) full_perm; ghost_write_pt r (v1 + 1); ghost_share_pt r; rewrite_slprop ((ghost_pts_to r (P.half_perm P.full_perm) (v1 + 1)) `star` (ghost_pts_to r (P.half_perm P.full_perm) (v1 + 1))) ((ghost_pts_to r half_perm (v1 + 1)) `star` (ghost_pts_to r half_perm (v2 + 1))) (fun _ -> ())
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.ni_ifc
val ni_ifc : Prims.unit
let ni_ifc = assert (forall h0 h1 s0. reify (ifc h0) s0 = reify (ifc h1) s0)
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 76, "end_line": 93, "start_col": 0, "start_line": 93 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post let pre = STINT?.pre let wp = STINT?.wp let get = STINT?.get let put = STINT?.put // We define a lift between PURE and STINT // -- this is analogous to the return for the monad // -- but automatically wiring the return here is not done yet unfold let lift_pure_stint (a:Type) (wp:pure_wp a) (n:int) (p:post a) = wp (fun a -> p (a, n)) sub_effect PURE ~> STINT = lift_pure_stint // We define an effect abbreviation for using pre-post conditions effect StInt (a:Type) (pre: pre) (post: (int -> a -> int -> GTot Type0)) = STINT a (fun n0 p -> pre n0 /\ (forall a n1. pre n0 /\ post n0 a n1 ==> p (a, n1))) // Another effect abbreviation for the trivial pre-post conditions effect StNull (a:Type) = STINT a (fun (n0:int) (p:(a * int) -> Type0) -> forall (x:(a * int)). p x) // We define an increment function that we verify intrinsically val incr_intrinsic : unit -> StInt unit (requires (fun n -> True)) (ensures (fun n0 _ n1 -> n1 = n0 + 1)) let incr_intrinsic u = let n = STINT?.get () in STINT?.put (n + 1) // Here is a weaker specification for increment val incr_intrinsic' : unit -> STINT unit (fun s0 post -> forall (s1:int). (s1 > s0) ==> post ((), s1)) let incr_intrinsic' u = let n = STINT?.get () in STINT?.put (n + 1) // Or, we can give increment the weakest possible spec and prove // properties extrinsically (after the fact) using reification val incr : unit -> StNull unit let incr u = let n = STINT?.get() in STINT?.put (n + 1) let incr_increases (s0:int) = assert (snd (reify (incr ()) s0) = s0 + 1) (* Using this extrinsic style we can also prove information-flow control properties of increment and decrement *) let decr () : StNull unit = let n = STINT?.get () in STINT?.put (n - 1) let ifc (h:bool) : StNull int = if h then (incr(); let y = STINT?.get() in decr(); y) else STINT?.get() + 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Prims.unit
Prims.Tot
[ "total" ]
[]
[ "Prims._assert", "Prims.l_Forall", "Prims.bool", "Prims.int", "Prims.b2t", "Prims.op_Equality", "FStar.Pervasives.Native.tuple2", "FStar.DM4F.IntST.ifc" ]
[]
false
false
false
true
false
let ni_ifc =
assert (forall h0 h1 s0. reify (ifc h0) s0 = reify (ifc h1) s0)
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.action_put
val action_put: x:int -> repr unit (fun n post -> post ((), x))
val action_put: x:int -> repr unit (fun n post -> post ((), x))
let action_put x i = ((), x)
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 102, "start_col": 0, "start_line": 102 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post let pre = STINT?.pre let wp = STINT?.wp let get = STINT?.get let put = STINT?.put // We define a lift between PURE and STINT // -- this is analogous to the return for the monad // -- but automatically wiring the return here is not done yet unfold let lift_pure_stint (a:Type) (wp:pure_wp a) (n:int) (p:post a) = wp (fun a -> p (a, n)) sub_effect PURE ~> STINT = lift_pure_stint // We define an effect abbreviation for using pre-post conditions effect StInt (a:Type) (pre: pre) (post: (int -> a -> int -> GTot Type0)) = STINT a (fun n0 p -> pre n0 /\ (forall a n1. pre n0 /\ post n0 a n1 ==> p (a, n1))) // Another effect abbreviation for the trivial pre-post conditions effect StNull (a:Type) = STINT a (fun (n0:int) (p:(a * int) -> Type0) -> forall (x:(a * int)). p x) // We define an increment function that we verify intrinsically val incr_intrinsic : unit -> StInt unit (requires (fun n -> True)) (ensures (fun n0 _ n1 -> n1 = n0 + 1)) let incr_intrinsic u = let n = STINT?.get () in STINT?.put (n + 1) // Here is a weaker specification for increment val incr_intrinsic' : unit -> STINT unit (fun s0 post -> forall (s1:int). (s1 > s0) ==> post ((), s1)) let incr_intrinsic' u = let n = STINT?.get () in STINT?.put (n + 1) // Or, we can give increment the weakest possible spec and prove // properties extrinsically (after the fact) using reification val incr : unit -> StNull unit let incr u = let n = STINT?.get() in STINT?.put (n + 1) let incr_increases (s0:int) = assert (snd (reify (incr ()) s0) = s0 + 1) (* Using this extrinsic style we can also prove information-flow control properties of increment and decrement *) let decr () : StNull unit = let n = STINT?.get () in STINT?.put (n - 1) let ifc (h:bool) : StNull int = if h then (incr(); let y = STINT?.get() in decr(); y) else STINT?.get() + 1 let ni_ifc = assert (forall h0 h1 s0. reify (ifc h0) s0 = reify (ifc h1) s0) (* Although we have STINT?.get and STINT?.put now as actions, *) (* we can also "rederive" them using reflection *) val action_get: (u:unit) -> repr int (fun n post -> post (n, n)) let action_get () i = (i, i)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> FStar.DM4F.IntST.repr Prims.unit (fun _ post -> post ((), x))
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let action_put x i =
((), x)
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.incr_increases
val incr_increases : s0: Prims.int -> Prims.unit
let incr_increases (s0:int) = assert (snd (reify (incr ()) s0) = s0 + 1)
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 72, "end_line": 80, "start_col": 0, "start_line": 80 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post let pre = STINT?.pre let wp = STINT?.wp let get = STINT?.get let put = STINT?.put // We define a lift between PURE and STINT // -- this is analogous to the return for the monad // -- but automatically wiring the return here is not done yet unfold let lift_pure_stint (a:Type) (wp:pure_wp a) (n:int) (p:post a) = wp (fun a -> p (a, n)) sub_effect PURE ~> STINT = lift_pure_stint // We define an effect abbreviation for using pre-post conditions effect StInt (a:Type) (pre: pre) (post: (int -> a -> int -> GTot Type0)) = STINT a (fun n0 p -> pre n0 /\ (forall a n1. pre n0 /\ post n0 a n1 ==> p (a, n1))) // Another effect abbreviation for the trivial pre-post conditions effect StNull (a:Type) = STINT a (fun (n0:int) (p:(a * int) -> Type0) -> forall (x:(a * int)). p x) // We define an increment function that we verify intrinsically val incr_intrinsic : unit -> StInt unit (requires (fun n -> True)) (ensures (fun n0 _ n1 -> n1 = n0 + 1)) let incr_intrinsic u = let n = STINT?.get () in STINT?.put (n + 1) // Here is a weaker specification for increment val incr_intrinsic' : unit -> STINT unit (fun s0 post -> forall (s1:int). (s1 > s0) ==> post ((), s1)) let incr_intrinsic' u = let n = STINT?.get () in STINT?.put (n + 1) // Or, we can give increment the weakest possible spec and prove // properties extrinsically (after the fact) using reification val incr : unit -> StNull unit let incr u = let n = STINT?.get() in STINT?.put (n + 1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s0: Prims.int -> Prims.unit
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims._assert", "Prims.b2t", "Prims.op_Equality", "FStar.Pervasives.Native.snd", "Prims.unit", "FStar.DM4F.IntST.incr", "Prims.op_Addition" ]
[]
false
false
false
true
false
let incr_increases (s0: int) =
assert (snd (reify (incr ()) s0) = s0 + 1)
false
FStar.DM4F.IntST.fst
FStar.DM4F.IntST.action_get
val action_get: (u:unit) -> repr int (fun n post -> post (n, n))
val action_get: (u:unit) -> repr int (fun n post -> post (n, n))
let action_get () i = (i, i)
{ "file_name": "examples/dm4free/FStar.DM4F.IntST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 99, "start_col": 0, "start_line": 99 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntST open FStar.DM4F.ST // A simple variant of state with a single integer as the state // Here is where all the DM4F magic happens let state = int total reifiable reflectable new_effect { STINT : a:Type -> Effect with repr = st state ; bind = bind_st state ; return = return_st state ; get = get state ; put = put state } // Some abbreviations let repr = STINT?.repr let post = STINT?.post let pre = STINT?.pre let wp = STINT?.wp let get = STINT?.get let put = STINT?.put // We define a lift between PURE and STINT // -- this is analogous to the return for the monad // -- but automatically wiring the return here is not done yet unfold let lift_pure_stint (a:Type) (wp:pure_wp a) (n:int) (p:post a) = wp (fun a -> p (a, n)) sub_effect PURE ~> STINT = lift_pure_stint // We define an effect abbreviation for using pre-post conditions effect StInt (a:Type) (pre: pre) (post: (int -> a -> int -> GTot Type0)) = STINT a (fun n0 p -> pre n0 /\ (forall a n1. pre n0 /\ post n0 a n1 ==> p (a, n1))) // Another effect abbreviation for the trivial pre-post conditions effect StNull (a:Type) = STINT a (fun (n0:int) (p:(a * int) -> Type0) -> forall (x:(a * int)). p x) // We define an increment function that we verify intrinsically val incr_intrinsic : unit -> StInt unit (requires (fun n -> True)) (ensures (fun n0 _ n1 -> n1 = n0 + 1)) let incr_intrinsic u = let n = STINT?.get () in STINT?.put (n + 1) // Here is a weaker specification for increment val incr_intrinsic' : unit -> STINT unit (fun s0 post -> forall (s1:int). (s1 > s0) ==> post ((), s1)) let incr_intrinsic' u = let n = STINT?.get () in STINT?.put (n + 1) // Or, we can give increment the weakest possible spec and prove // properties extrinsically (after the fact) using reification val incr : unit -> StNull unit let incr u = let n = STINT?.get() in STINT?.put (n + 1) let incr_increases (s0:int) = assert (snd (reify (incr ()) s0) = s0 + 1) (* Using this extrinsic style we can also prove information-flow control properties of increment and decrement *) let decr () : StNull unit = let n = STINT?.get () in STINT?.put (n - 1) let ifc (h:bool) : StNull int = if h then (incr(); let y = STINT?.get() in decr(); y) else STINT?.get() + 1 let ni_ifc = assert (forall h0 h1 s0. reify (ifc h0) s0 = reify (ifc h1) s0) (* Although we have STINT?.get and STINT?.put now as actions, *) (* we can also "rederive" them using reflection *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.ST.fst.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntST.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
u266: Prims.unit -> FStar.DM4F.IntST.repr Prims.int (fun n post -> post (n, n))
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let action_get () i =
(i, i)
false
Spec.Exponentiation.fst
Spec.Exponentiation.exp_mont_ladder_swap_lemma
val exp_mont_ladder_swap_lemma: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> Lemma (k.to.refl (exp_mont_ladder_swap k a bBits b) == S.exp_mont_ladder_swap k.to.comm_monoid (k.to.refl a) bBits b)
val exp_mont_ladder_swap_lemma: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> Lemma (k.to.refl (exp_mont_ladder_swap k a bBits b) == S.exp_mont_ladder_swap k.to.comm_monoid (k.to.refl a) bBits b)
let exp_mont_ladder_swap_lemma #t k a bBits b = exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
{ "file_name": "specs/Spec.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 67, "start_col": 0, "start_line": 66 }
module Spec.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence module S = Lib.Exponentiation module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 1" val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in k.to.refl acc == accs /\ k.to.refl c == cs) let rec exp_rl_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a) in let inp1 = (one, a) in let f0 = S.exp_rl_f k.to.comm_monoid bBits b in let f1 = exp_rl_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_rl_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_rl_lemma #t k a bBits b = exp_rl_lemma_loop #t k a bBits b bBits val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (r0s, r1s, sws) = Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in let (r0, r1, sw) = Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws) let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a, 0) in let inp1 = (one, a, 0) in let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in let f1 = exp_mont_ladder_swap_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": 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
k: Spec.Exponentiation.concrete_ops t -> a: t -> bBits: Prims.nat -> b: Prims.nat{b < Prims.pow2 bBits} -> FStar.Pervasives.Lemma (ensures Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) (Spec.Exponentiation.exp_mont_ladder_swap k a bBits b) == Lib.Exponentiation.exp_mont_ladder_swap (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k)) (Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a) bBits b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Exponentiation.concrete_ops", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Spec.Exponentiation.exp_mont_ladder_swap_lemma_loop", "Prims.unit" ]
[]
true
false
true
false
false
let exp_mont_ladder_swap_lemma #t k a bBits b =
exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
false
Lib.IntTypes.fst
Lib.IntTypes.pow2_3
val pow2_3: n:nat -> Lemma (pow2 3 = 8) [SMTPat (pow2 n)]
val pow2_3: n:nat -> Lemma (pow2 3 = 8) [SMTPat (pow2 n)]
let pow2_3 _ = assert_norm (pow2 3 = 8)
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 8, "start_col": 0, "start_line": 8 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> FStar.Pervasives.Lemma (ensures Prims.pow2 3 = 8) [SMTPat (Prims.pow2 n)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.pow2", "Prims.unit" ]
[]
true
false
true
false
false
let pow2_3 _ =
assert_norm (pow2 3 = 8)
false
Lib.IntTypes.fst
Lib.IntTypes.pow2_2
val pow2_2: n:nat -> Lemma (pow2 2 = 4) [SMTPat (pow2 n)]
val pow2_2: n:nat -> Lemma (pow2 2 = 4) [SMTPat (pow2 n)]
let pow2_2 _ = assert_norm (pow2 2 = 4)
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 7, "start_col": 0, "start_line": 7 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> FStar.Pervasives.Lemma (ensures Prims.pow2 2 = 4) [SMTPat (Prims.pow2 n)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.pow2", "Prims.unit" ]
[]
true
false
true
false
false
let pow2_2 _ =
assert_norm (pow2 2 = 4)
false
Lib.IntTypes.fst
Lib.IntTypes.pow2_4
val pow2_4: n:nat -> Lemma (pow2 4 = 16) [SMTPat (pow2 n)]
val pow2_4: n:nat -> Lemma (pow2 4 = 16) [SMTPat (pow2 n)]
let pow2_4 _ = assert_norm (pow2 4 = 16)
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 9, "start_col": 0, "start_line": 9 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200" let pow2_2 _ = assert_norm (pow2 2 = 4)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> FStar.Pervasives.Lemma (ensures Prims.pow2 4 = 16) [SMTPat (Prims.pow2 n)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.pow2", "Prims.unit" ]
[]
true
false
true
false
false
let pow2_4 _ =
assert_norm (pow2 4 = 16)
false
Spec.Exponentiation.fst
Spec.Exponentiation.pow_lemma
val pow_lemma: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> Lemma (k.to.refl (pow k a b) == S.pow k.to.comm_monoid (k.to.refl a) b)
val pow_lemma: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> Lemma (k.to.refl (pow k a b) == S.pow k.to.comm_monoid (k.to.refl a) b)
let rec pow_lemma #t k a b = if b = 0 then () else pow_lemma k a (b - 1)
{ "file_name": "specs/Spec.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 96, "start_col": 0, "start_line": 94 }
module Spec.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence module S = Lib.Exponentiation module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 1" val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in k.to.refl acc == accs /\ k.to.refl c == cs) let rec exp_rl_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a) in let inp1 = (one, a) in let f0 = S.exp_rl_f k.to.comm_monoid bBits b in let f1 = exp_rl_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_rl_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_rl_lemma #t k a bBits b = exp_rl_lemma_loop #t k a bBits b bBits val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (r0s, r1s, sws) = Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in let (r0, r1, sw) = Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws) let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a, 0) in let inp1 = (one, a, 0) in let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in let f1 = exp_mont_ladder_swap_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_mont_ladder_swap_lemma #t k a bBits b = exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} -> Lemma ( let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in let acc = Loops.repeat i k.sqr a in k.to.refl acc == accs) let rec exp_pow2_lemma_loop #t k a b i = if i = 0 then begin Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a); Loops.eq_repeat0 k.sqr a end else begin exp_pow2_lemma_loop #t k a b (i - 1); Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1); Loops.unfold_repeat b k.sqr a (i - 1) end let exp_pow2_lemma #t k a b = exp_pow2_lemma_loop k a b b #push-options "--fuel 1" let pow_eq0 #t k a = () let pow_unfold #t k a i = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": 1, "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": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Spec.Exponentiation.concrete_ops t -> a: t -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) (Spec.Exponentiation.pow k a b) == Lib.Exponentiation.Definition.pow (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k)) (Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a) b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Exponentiation.concrete_ops", "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "Spec.Exponentiation.pow_lemma", "Prims.op_Subtraction", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec pow_lemma #t k a b =
if b = 0 then () else pow_lemma k a (b - 1)
false
Spec.Exponentiation.fst
Spec.Exponentiation.exp_rl_lemma
val exp_rl_lemma: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> Lemma (k.to.refl (exp_rl k a bBits b) == S.exp_rl k.to.comm_monoid (k.to.refl a) bBits b)
val exp_rl_lemma: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> Lemma (k.to.refl (exp_rl k a bBits b) == S.exp_rl k.to.comm_monoid (k.to.refl a) bBits b)
let exp_rl_lemma #t k a bBits b = exp_rl_lemma_loop #t k a bBits b bBits
{ "file_name": "specs/Spec.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 38, "start_col": 0, "start_line": 37 }
module Spec.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence module S = Lib.Exponentiation module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 1" val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in k.to.refl acc == accs /\ k.to.refl c == cs) let rec exp_rl_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a) in let inp1 = (one, a) in let f0 = S.exp_rl_f k.to.comm_monoid bBits b in let f1 = exp_rl_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_rl_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": 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
k: Spec.Exponentiation.concrete_ops t -> a: t -> bBits: Prims.nat -> b: Prims.nat{b < Prims.pow2 bBits} -> FStar.Pervasives.Lemma (ensures Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) (Spec.Exponentiation.exp_rl k a bBits b) == Lib.Exponentiation.exp_rl (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k)) (Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a) bBits b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Exponentiation.concrete_ops", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Spec.Exponentiation.exp_rl_lemma_loop", "Prims.unit" ]
[]
true
false
true
false
false
let exp_rl_lemma #t k a bBits b =
exp_rl_lemma_loop #t k a bBits b bBits
false
Lib.IntTypes.fst
Lib.IntTypes.sec_int_v
val sec_int_v: #t:inttype -> sec_int_t t -> range_t t
val sec_int_v: #t:inttype -> sec_int_t t -> range_t t
let sec_int_v #t u = pub_int_v u
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 16, "start_col": 0, "start_line": 16 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200" let pow2_2 _ = assert_norm (pow2 2 = 4) let pow2_3 _ = assert_norm (pow2 3 = 8) let pow2_4 _ = assert_norm (pow2 4 = 16) let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000) let bits_numbytes t = () let sec_int_t t = pub_int_t t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
u100: Lib.IntTypes.sec_int_t t -> Lib.IntTypes.range_t t
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.inttype", "Lib.IntTypes.sec_int_t", "Lib.IntTypes.pub_int_v", "Lib.IntTypes.range_t" ]
[]
false
false
false
false
false
let sec_int_v #t u =
pub_int_v u
false
Lib.IntTypes.fst
Lib.IntTypes.pow2_127
val pow2_127: n:nat -> Lemma (pow2 127 = 0x80000000000000000000000000000000) [SMTPat (pow2 n)]
val pow2_127: n:nat -> Lemma (pow2 127 = 0x80000000000000000000000000000000) [SMTPat (pow2 n)]
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 10, "start_col": 0, "start_line": 10 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200" let pow2_2 _ = assert_norm (pow2 2 = 4) let pow2_3 _ = assert_norm (pow2 3 = 8)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> FStar.Pervasives.Lemma (ensures Prims.pow2 127 = 0x80000000000000000000000000000000) [SMTPat (Prims.pow2 n)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.pow2", "Prims.unit" ]
[]
true
false
true
false
false
let pow2_127 _ =
assert_norm (pow2 127 = 0x80000000000000000000000000000000)
false
Spec.Exponentiation.fst
Spec.Exponentiation.exp_mont_ladder_swap_lemma_loop
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (r0s, r1s, sws) = Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in let (r0, r1, sw) = Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (r0s, r1s, sws) = Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in let (r0, r1, sw) = Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a, 0) in let inp1 = (one, a, 0) in let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in let f1 = exp_mont_ladder_swap_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end
{ "file_name": "specs/Spec.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 63, "start_col": 0, "start_line": 50 }
module Spec.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence module S = Lib.Exponentiation module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 1" val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in k.to.refl acc == accs /\ k.to.refl c == cs) let rec exp_rl_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a) in let inp1 = (one, a) in let f0 = S.exp_rl_f k.to.comm_monoid bBits b in let f1 = exp_rl_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_rl_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_rl_lemma #t k a bBits b = exp_rl_lemma_loop #t k a bBits b bBits val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (r0s, r1s, sws) = Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in let (r0, r1, sw) = Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": 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
k: Spec.Exponentiation.concrete_ops t -> a: t -> bBits: Prims.nat -> b: Prims.nat{b < Prims.pow2 bBits} -> i: Prims.nat{i <= bBits} -> FStar.Pervasives.Lemma (ensures (let one = Mkconcrete_ops?.one k () in let _ = Lib.LoopCombinators.repeati i (Lib.Exponentiation.exp_mont_ladder_swap_f (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k)) bBits b) (Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) one, Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a, 0) in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ r0s r1s sws = _ in let _ = Lib.LoopCombinators.repeati i (Spec.Exponentiation.exp_mont_ladder_swap_f k bBits b) (one, a, 0) in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ r0 r1 sw = _ in Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) r0 == r0s /\ Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) r1 == r1s /\ sw == sws) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Exponentiation.concrete_ops", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Lib.LoopCombinators.eq_repeati0", "FStar.Pervasives.Native.tuple3", "Prims.unit", "Spec.Exponentiation.__proj__Mkto_comm_monoid__item__a_spec", "Spec.Exponentiation.__proj__Mkconcrete_ops__item__to", "Prims.bool", "Lib.LoopCombinators.unfold_repeati", "Prims.op_Subtraction", "Spec.Exponentiation.exp_mont_ladder_swap_lemma_loop", "Spec.Exponentiation.exp_mont_ladder_swap_f", "Lib.Exponentiation.exp_mont_ladder_swap_f", "Spec.Exponentiation.__proj__Mkto_comm_monoid__item__comm_monoid", "FStar.Pervasives.Native.Mktuple3", "Spec.Exponentiation.__proj__Mkto_comm_monoid__item__refl", "Spec.Exponentiation.__proj__Mkconcrete_ops__item__one" ]
[ "recursion" ]
false
false
true
false
false
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i =
let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a, 0) in let inp1 = (one, a, 0) in let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in let f1 = exp_mont_ladder_swap_f k bBits b in if i = 0 then (Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1) else (exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1))
false
Pulse.Soundness.WithLocal.fst
Pulse.Soundness.WithLocal.withlocal_soundness
val withlocal_soundness (#g:stt_env) (#t:st_term) (#c:comp) (d:st_typing g t c{T_WithLocal? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val withlocal_soundness (#g:stt_env) (#t:st_term) (#c:comp) (d:st_typing g t c{T_WithLocal? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let withlocal_soundness #g #t #c d soundness = let T_WithLocal _ _ init body init_t c x init_typing init_t_typing c_typing body_typing = d in let CT_ST _ st st_typing = c_typing in let rg = elab_env g in let ru = comp_u c in let ra = elab_term init_t in let rinit = elab_term init in let rpre = elab_term (comp_pre c) in let rret_t = elab_term (comp_res c) in let rpost = elab_term (comp_post c) in let rbody = elab_st_typing body_typing in let a_typing = tot_typing_soundness init_t_typing in let rinit_typing = tot_typing_soundness init_typing in let cres_typing, cpre_typing, cpost_typing = Pulse.Soundness.Comp.stc_soundness st_typing in let pre_typing = cpre_typing in let ret_t_typing = cres_typing in let post_typing = cpost_typing in elab_push_binding g x (mk_ref init_t); let rbody_typing = soundness _ _ _ body_typing in WT.with_local_typing #rg #ru #ra #rinit #rpre #rret_t #rpost #rbody x a_typing rinit_typing pre_typing ret_t_typing post_typing rbody_typing
{ "file_name": "lib/steel/pulse/Pulse.Soundness.WithLocal.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 16, "end_line": 69, "start_col": 0, "start_line": 29 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness.WithLocal open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate.Core open Pulse.Elaborate open Pulse.Soundness.Common module WT = Pulse.Steel.Wrapper.Typing
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Steel.Wrapper.Typing.fsti.checked", "Pulse.Soundness.Comp.fsti.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.Core.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.WithLocal.fst" }
[ { "abbrev": true, "full_module": "Pulse.Steel.Wrapper.Typing", "short_module": "WT" }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Core", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 8, "initial_ifuel": 1, "max_fuel": 8, "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: Pulse.Typing.st_typing g t c {T_WithLocal? d} -> soundness: Pulse.Soundness.Common.soundness_t d -> Prims.GTot (FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Prims.b2t", "Pulse.Typing.uu___is_T_WithLocal", "Pulse.Soundness.Common.soundness_t", "Pulse.Typing.Env.env", "Pulse.Syntax.Base.ppname", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.uu___is_C_ST", "Pulse.Syntax.Base.var", "Prims.l_and", "FStar.Pervasives.Native.uu___is_None", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.lookup", "Prims.l_not", "FStar.Set.mem", "Pulse.Syntax.Naming.freevars_st", "Pulse.Typing.tot_typing", "Pulse.Typing.universe_of", "Pulse.Syntax.Pure.u0", "Pulse.Typing.comp_typing_u", "Pulse.Typing.Env.push_binding", "Pulse.Syntax.Base.ppname_default", "Pulse.Typing.mk_ref", "Pulse.Syntax.Naming.open_st_term_nv", "Pulse.Syntax.Base.v_as_nv", "Pulse.Typing.comp_withlocal_body", "Pulse.Syntax.Base.st_comp", "Pulse.Typing.st_comp_typing", "FStar.Reflection.Typing.tot_typing", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_term", "Pulse.Syntax.Base.__proj__Mkst_comp__item__res", "FStar.Reflection.Typing.tm_type", "Pulse.Syntax.Base.__proj__Mkst_comp__item__u", "Pulse.Syntax.Base.__proj__Mkst_comp__item__pre", "Pulse.Reflection.Util.vprop_tm", "Pulse.Reflection.Util.mk_abs", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "Pulse.Syntax.Base.__proj__Mkst_comp__item__post", "Pulse.Soundness.Common.post1_type_bind", "Pulse.Steel.Wrapper.Typing.with_local_typing", "Pulse.Elaborate.Core.elab_st_typing", "Pulse.Elaborate.Pure.elab_comp", "Prims.unit", "Pulse.Typing.elab_push_binding", "FStar.Pervasives.Native.tuple3", "Pulse.Soundness.Comp.stc_soundness", "Pulse.Soundness.Common.tot_typing_soundness", "Pulse.Syntax.Pure.tm_type", "FStar.Stubs.Reflection.Types.term", "Pulse.Syntax.Base.comp_post", "Pulse.Syntax.Base.comp_res", "Pulse.Syntax.Base.comp_pre", "Pulse.Syntax.Base.universe", "Pulse.Syntax.Base.comp_u", "FStar.Stubs.Reflection.Types.env" ]
[]
false
false
false
false
false
let withlocal_soundness #g #t #c d soundness =
let T_WithLocal _ _ init body init_t c x init_typing init_t_typing c_typing body_typing = d in let CT_ST _ st st_typing = c_typing in let rg = elab_env g in let ru = comp_u c in let ra = elab_term init_t in let rinit = elab_term init in let rpre = elab_term (comp_pre c) in let rret_t = elab_term (comp_res c) in let rpost = elab_term (comp_post c) in let rbody = elab_st_typing body_typing in let a_typing = tot_typing_soundness init_t_typing in let rinit_typing = tot_typing_soundness init_typing in let cres_typing, cpre_typing, cpost_typing = Pulse.Soundness.Comp.stc_soundness st_typing in let pre_typing = cpre_typing in let ret_t_typing = cres_typing in let post_typing = cpost_typing in elab_push_binding g x (mk_ref init_t); let rbody_typing = soundness _ _ _ body_typing in WT.with_local_typing #rg #ru #ra #rinit #rpre #rret_t #rpost #rbody x a_typing rinit_typing pre_typing ret_t_typing post_typing rbody_typing
false
Spec.Exponentiation.fst
Spec.Exponentiation.exp_pow2_lemma
val exp_pow2_lemma: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> Lemma (k.to.refl (exp_pow2 k a b) == S.exp_pow2 k.to.comm_monoid (k.to.refl a) b)
val exp_pow2_lemma: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> Lemma (k.to.refl (exp_pow2 k a b) == S.exp_pow2 k.to.comm_monoid (k.to.refl a) b)
let exp_pow2_lemma #t k a b = exp_pow2_lemma_loop k a b b
{ "file_name": "specs/Spec.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 87, "start_col": 0, "start_line": 86 }
module Spec.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence module S = Lib.Exponentiation module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 1" val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in k.to.refl acc == accs /\ k.to.refl c == cs) let rec exp_rl_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a) in let inp1 = (one, a) in let f0 = S.exp_rl_f k.to.comm_monoid bBits b in let f1 = exp_rl_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_rl_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_rl_lemma #t k a bBits b = exp_rl_lemma_loop #t k a bBits b bBits val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (r0s, r1s, sws) = Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in let (r0, r1, sw) = Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws) let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a, 0) in let inp1 = (one, a, 0) in let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in let f1 = exp_mont_ladder_swap_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_mont_ladder_swap_lemma #t k a bBits b = exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} -> Lemma ( let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in let acc = Loops.repeat i k.sqr a in k.to.refl acc == accs) let rec exp_pow2_lemma_loop #t k a b i = if i = 0 then begin Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a); Loops.eq_repeat0 k.sqr a end else begin exp_pow2_lemma_loop #t k a b (i - 1); Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1); Loops.unfold_repeat b k.sqr a (i - 1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": 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
k: Spec.Exponentiation.concrete_ops t -> a: t -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) (Spec.Exponentiation.exp_pow2 k a b) == Lib.Exponentiation.exp_pow2 (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k)) (Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a) b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Exponentiation.concrete_ops", "Prims.nat", "Spec.Exponentiation.exp_pow2_lemma_loop", "Prims.unit" ]
[]
true
false
true
false
false
let exp_pow2_lemma #t k a b =
exp_pow2_lemma_loop k a b b
false
Vale.AES.X64.AES256.fsti
Vale.AES.X64.AES256.va_wp_AES256EncryptBlock
val va_wp_AES256EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
val va_wp_AES256EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0
let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64 rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input ==> va_k va_sM (())))
{ "file_name": "obj/Vale.AES.X64.AES256.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 73, "end_line": 156, "start_col": 0, "start_line": 144 }
module Vale.AES.X64.AES256 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.Arch.Types open Vale.AES.AES256_helpers open Vale.X64.CPU_Features_s #reset-options "--z3rlimit 20" //-- KeyExpansion256Stdcall val va_code_KeyExpansion256Stdcall : win:bool -> Tot va_code val va_codegen_success_KeyExpansion256Stdcall : win:bool -> Tot va_pbool val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall win) va_s0 /\ va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==> Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) j)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==> Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion256Stdcall : win:bool -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win)) = (va_QProc (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem]) (va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion256Stdcall win input_key_b output_key_expansion_b)) //-- //-- AES256EncryptBlock val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64 rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM va_s0))))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES256_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AES256.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
input: Vale.X64.Decls.quad32 -> key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> round_keys: FStar.Seq.Base.seq Vale.X64.Decls.quad32 -> keys_buffer: Vale.X64.Memory.buffer128 -> va_s0: Vale.X64.Decls.va_state -> va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0) -> Type0
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.quad32", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Vale.X64.Memory.buffer128", "Vale.X64.Decls.va_state", "Prims.unit", "Prims.l_and", "Prims.b2t", "Vale.X64.Decls.va_get_ok", "Vale.X64.CPU_Features_s.aesni_enabled", "Vale.X64.CPU_Features_s.sse_enabled", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.AES_common_s.AES_256", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "Vale.AES.AES_s.key_to_round_keys_LE", "Vale.X64.Decls.va_get_xmm", "Vale.X64.Decls.va_get_reg64", "Vale.X64.Machine_s.rR8", "Vale.X64.Memory.buffer_addr", "Vale.X64.Memory.vuint128", "Vale.X64.Decls.va_get_mem_heaplet", "Vale.X64.Decls.validSrcAddrs128", "Vale.X64.Decls.va_get_mem_layout", "Vale.Arch.HeapTypes_s.Secret", "Prims.l_Forall", "Prims.nat", "Prims.l_imp", "Prims.op_LessThan", "Vale.X64.Decls.buffer128_read", "FStar.Seq.Base.index", "Vale.X64.Flags.t", "Vale.Def.Types_s.quad32", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.X64.State.vale_state", "Vale.X64.Decls.va_upd_flags", "Vale.X64.Decls.va_upd_xmm" ]
[]
false
false
false
true
true
let va_wp_AES256EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) (va_s0: va_state) (va_k: (va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64 rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i: nat). i < 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0: quad32) (va_x_xmm2: quad32) (va_x_efl: Vale.X64.Flags.t). let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input ==> va_k va_sM (())))
false
Spec.Exponentiation.fst
Spec.Exponentiation.exp_pow2_lemma_loop
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} -> Lemma ( let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in let acc = Loops.repeat i k.sqr a in k.to.refl acc == accs)
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} -> Lemma ( let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in let acc = Loops.repeat i k.sqr a in k.to.refl acc == accs)
let rec exp_pow2_lemma_loop #t k a b i = if i = 0 then begin Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a); Loops.eq_repeat0 k.sqr a end else begin exp_pow2_lemma_loop #t k a b (i - 1); Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1); Loops.unfold_repeat b k.sqr a (i - 1) end
{ "file_name": "specs/Spec.Exponentiation.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 83, "start_col": 0, "start_line": 76 }
module Spec.Exponentiation open FStar.Mul open Lib.IntTypes open Lib.Sequence module S = Lib.Exponentiation module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 1" val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in k.to.refl acc == accs /\ k.to.refl c == cs) let rec exp_rl_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a) in let inp1 = (one, a) in let f0 = S.exp_rl_f k.to.comm_monoid bBits b in let f1 = exp_rl_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_rl_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_rl_lemma #t k a bBits b = exp_rl_lemma_loop #t k a bBits b bBits val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} -> Lemma (let one = k.one () in let (r0s, r1s, sws) = Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in let (r0, r1, sw) = Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws) let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i = let one = k.one () in let inp0 = (k.to.refl one, k.to.refl a, 0) in let inp1 = (one, a, 0) in let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in let f1 = exp_mont_ladder_swap_f k bBits b in if i = 0 then begin Loops.eq_repeati0 bBits f0 inp0; Loops.eq_repeati0 bBits f1 inp1 end else begin exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1); Loops.unfold_repeati bBits f0 inp0 (i - 1); Loops.unfold_repeati bBits f1 inp1 (i - 1) end let exp_mont_ladder_swap_lemma #t k a bBits b = exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} -> Lemma ( let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in let acc = Loops.repeat i k.sqr a in k.to.refl acc == accs)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Exponentiation.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "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": 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
k: Spec.Exponentiation.concrete_ops t -> a: t -> b: Prims.nat -> i: Prims.nat{i <= b} -> FStar.Pervasives.Lemma (ensures (let accs = Lib.LoopCombinators.repeat i (Lib.Exponentiation.Definition.sqr (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k) )) (Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a) in let acc = Lib.LoopCombinators.repeat i (Mkconcrete_ops?.sqr k) a in Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc == accs))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Exponentiation.concrete_ops", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.int", "Lib.LoopCombinators.eq_repeat0", "Spec.Exponentiation.__proj__Mkconcrete_ops__item__sqr", "Prims.unit", "Spec.Exponentiation.__proj__Mkto_comm_monoid__item__a_spec", "Spec.Exponentiation.__proj__Mkconcrete_ops__item__to", "Lib.Exponentiation.Definition.sqr", "Spec.Exponentiation.__proj__Mkto_comm_monoid__item__comm_monoid", "Spec.Exponentiation.__proj__Mkto_comm_monoid__item__refl", "Prims.bool", "Lib.LoopCombinators.unfold_repeat", "Prims.op_Subtraction", "Spec.Exponentiation.exp_pow2_lemma_loop" ]
[ "recursion" ]
false
false
true
false
false
let rec exp_pow2_lemma_loop #t k a b i =
if i = 0 then (Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a); Loops.eq_repeat0 k.sqr a) else (exp_pow2_lemma_loop #t k a b (i - 1); Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1); Loops.unfold_repeat b k.sqr a (i - 1))
false
Lib.IntTypes.fst
Lib.IntTypes.sec_int_t
val sec_int_t: inttype -> Type0
val sec_int_t: inttype -> Type0
let sec_int_t t = pub_int_t t
{ "file_name": "lib/Lib.IntTypes.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 14, "start_col": 0, "start_line": 14 }
module Lib.IntTypes open FStar.Math.Lemmas #push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200" let pow2_2 _ = assert_norm (pow2 2 = 4) let pow2_3 _ = assert_norm (pow2 3 = 8) let pow2_4 _ = assert_norm (pow2 4 = 16) let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000) let bits_numbytes t = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.Cast.Full.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Int.fsti.checked", "FStar.BitVector.fst.checked" ], "interface_file": true, "source_file": "Lib.IntTypes.fst" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Lib.IntTypes.inttype -> Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.inttype", "Lib.IntTypes.pub_int_t" ]
[]
false
false
false
true
true
let sec_int_t t =
pub_int_t t
false
Vale.AES.X64.AES256.fsti
Vale.AES.X64.AES256.va_quick_AES256EncryptBlock
val va_quick_AES256EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ()))
val va_quick_AES256EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ()))
let va_quick_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ())) = (va_QProc (va_code_AES256EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0]) (va_wp_AES256EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES256EncryptBlock input key round_keys keys_buffer))
{ "file_name": "obj/Vale.AES.X64.AES256.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 170, "start_col": 0, "start_line": 166 }
module Vale.AES.X64.AES256 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.Arch.Types open Vale.AES.AES256_helpers open Vale.X64.CPU_Features_s #reset-options "--z3rlimit 20" //-- KeyExpansion256Stdcall val va_code_KeyExpansion256Stdcall : win:bool -> Tot va_code val va_codegen_success_KeyExpansion256Stdcall : win:bool -> Tot va_pbool val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall win) va_s0 /\ va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==> Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) j)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==> Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion256Stdcall : win:bool -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) [@ "opaque_to_smt" va_qattr] let va_quick_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win)) = (va_QProc (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem]) (va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion256Stdcall win input_key_b output_key_expansion_b)) //-- //-- AES256EncryptBlock val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64 rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #quad32 round_keys i))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM va_s0)))))) [@ va_qattr] let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64 rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input ==> va_k va_sM (()))) val va_wpProof_AES256EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlock input key round_keys keys_buffer va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0]) va_s0 va_k ((va_sM, va_f0, va_g))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES256_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AES256.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
input: Vale.X64.Decls.quad32 -> key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 -> round_keys: FStar.Seq.Base.seq Vale.X64.Decls.quad32 -> keys_buffer: Vale.X64.Memory.buffer128 -> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.AES.X64.AES256.va_code_AES256EncryptBlock ())
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Decls.quad32", "FStar.Seq.Base.seq", "Vale.X64.Memory.nat32", "Vale.X64.Memory.buffer128", "Vale.X64.QuickCode.va_QProc", "Prims.unit", "Vale.AES.X64.AES256.va_code_AES256EncryptBlock", "Prims.Cons", "Vale.X64.QuickCode.mod_t", "Vale.X64.QuickCode.va_Mod_flags", "Vale.X64.QuickCode.va_Mod_xmm", "Prims.Nil", "Vale.AES.X64.AES256.va_wp_AES256EncryptBlock", "Vale.AES.X64.AES256.va_wpProof_AES256EncryptBlock", "Vale.X64.QuickCode.va_quickCode" ]
[]
false
false
false
false
false
let va_quick_AES256EncryptBlock (input: quad32) (key: (seq nat32)) (round_keys: (seq quad32)) (keys_buffer: buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ())) =
(va_QProc (va_code_AES256EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0]) (va_wp_AES256EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES256EncryptBlock input key round_keys keys_buffer))
false
Vale.AES.X64.AES256.fsti
Vale.AES.X64.AES256.va_quick_KeyExpansion256Stdcall
val va_quick_KeyExpansion256Stdcall (win: bool) (input_key_b output_key_expansion_b: buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win))
val va_quick_KeyExpansion256Stdcall (win: bool) (input_key_b output_key_expansion_b: buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win))
let va_quick_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128) (output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win)) = (va_QProc (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem]) (va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion256Stdcall win input_key_b output_key_expansion_b))
{ "file_name": "obj/Vale.AES.X64.AES256.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 119, "start_col": 0, "start_line": 114 }
module Vale.AES.X64.AES256 open Vale.Def.Opaque_s open Vale.Def.Types_s open FStar.Seq open Vale.AES.AES_s open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.InsMem open Vale.X64.InsVector open Vale.X64.InsAes open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.Arch.Types open Vale.AES.AES256_helpers open Vale.X64.CPU_Features_s #reset-options "--z3rlimit 20" //-- KeyExpansion256Stdcall val va_code_KeyExpansion256Stdcall : win:bool -> Tot va_code val va_codegen_success_KeyExpansion256Stdcall : win:bool -> Tot va_pbool val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> Ghost (va_state & va_fuel) (requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall win) va_s0 /\ va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret))) (ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==> Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) j)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64 rRdx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) [@ va_qattr] let va_wp_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128) (output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 = (va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap) (va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==> Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) j)) ==> va_k va_sM (()))) val va_wpProof_KeyExpansion256Stdcall : win:bool -> input_key_b:buffer128 -> output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0) -> Ghost (va_state & va_fuel & unit) (requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b va_s0 va_k)) (ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsVector.fsti.checked", "Vale.X64.InsMem.fsti.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.InsAes.fsti.checked", "Vale.X64.Flags.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.AES_s.fst.checked", "Vale.AES.AES256_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.Base.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.X64.AES256.fsti" }
[ { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES256_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsAes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsVector", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsMem", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
win: Prims.bool -> input_key_b: Vale.X64.Memory.buffer128 -> output_key_expansion_b: Vale.X64.Memory.buffer128 -> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.AES.X64.AES256.va_code_KeyExpansion256Stdcall win)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Vale.X64.Memory.buffer128", "Vale.X64.QuickCode.va_QProc", "Prims.unit", "Vale.AES.X64.AES256.va_code_KeyExpansion256Stdcall", "Prims.Cons", "Vale.X64.QuickCode.mod_t", "Vale.X64.QuickCode.va_Mod_flags", "Vale.X64.QuickCode.va_Mod_xmm", "Vale.X64.QuickCode.va_Mod_mem_heaplet", "Vale.X64.QuickCode.va_Mod_reg64", "Vale.X64.Machine_s.rRdx", "Vale.X64.QuickCode.va_Mod_mem", "Prims.Nil", "Vale.AES.X64.AES256.va_wp_KeyExpansion256Stdcall", "Vale.AES.X64.AES256.va_wpProof_KeyExpansion256Stdcall", "Vale.X64.QuickCode.va_quickCode" ]
[]
false
false
false
false
false
let va_quick_KeyExpansion256Stdcall (win: bool) (input_key_b output_key_expansion_b: buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win)) =
(va_QProc (va_code_KeyExpansion256Stdcall win) ([ va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem ]) (va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b) (va_wpProof_KeyExpansion256Stdcall win input_key_b output_key_expansion_b))
false