effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
FStar.Pervasives.Lemma
val slice_append_back (#a: Type) (x y: seq a) (i: nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); ()
val slice_append_back (#a: Type) (x y: seq a) (i: nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) let slice_append_back (#a: Type) (x y: seq a) (i: nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) =
false
null
true
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Prims.nat", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "FStar.Seq.Base.append", "Prims.op_Subtraction", "FStar.Seq.Base.length", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
false
false
Vale.AES.GCM.fst
{ "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val slice_append_back (#a: Type) (x y: seq a) (i: nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
[]
Vale.AES.GCM.slice_append_back
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: FStar.Seq.Base.seq a -> y: FStar.Seq.Base.seq a -> i: Prims.nat -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length x <= i /\ i <= FStar.Seq.Base.length x + FStar.Seq.Base.length y) (ensures FStar.Seq.Base.slice (FStar.Seq.Base.append x y) 0 i == FStar.Seq.Base.append x (FStar.Seq.Base.slice y 0 (i - FStar.Seq.Base.length x)))
{ "end_col": 4, "end_line": 319, "start_col": 2, "start_line": 318 }
FStar.Pervasives.Lemma
val lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv)
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); ()
val lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) let lemma_compute_iv_hard (iv: supported_iv_LE) (quads: seq quad32) (length_quad h_LE j0: quad32) : Lemma (requires ~(length iv == 96 / 8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) =
false
null
true
assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.GCM_s.supported_iv_LE", "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.unit", "Vale.AES.GCM_s.compute_iv_BE_reveal", "Vale.AES.GHash.ghash_incremental_to_ghash", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "Prims._assert", "Prims.eq2", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Types_s.insert_nat64_def", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "FStar.Mul.op_Star", "FStar.Seq.Base.length", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.insert_nat64_reveal", "Vale.Def.Words_s.four", "Vale.Def.Types_s.insert_nat64", "Vale.Arch.Types.lemma_insert_nat64_nat32s", "Vale.Def.Words_s.nat32", "Prims.int", "Vale.Arch.Types.two_to_nat32", "Vale.Def.Words_s.Mktwo", "Prims.l_and", "Prims.l_not", "Prims.op_Division", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "Vale.AES.GHash.ghash_incremental", "Prims.squash", "Vale.AES.GCM_s.compute_iv_BE", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv)
false
false
Vale.AES.GCM.fst
{ "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" }
null
val lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv)
[]
Vale.AES.GCM.lemma_compute_iv_hard
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
iv: Vale.AES.GCM_s.supported_iv_LE -> quads: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> length_quad: Vale.Def.Types_s.quad32 -> h_LE: Vale.Def.Types_s.quad32 -> j0: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires ~(FStar.Seq.Base.length iv == 96 / 8) /\ quads == Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.AES.GCTR_s.pad_to_128_bits iv) /\ j0 == Vale.AES.GHash.ghash_incremental h_LE (Vale.Def.Words_s.Mkfour 0 0 0 0) (FStar.Seq.Base.append quads (FStar.Seq.Base.create 1 length_quad)) /\ length_quad == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour 0 0 0 0) 0 1) (8 * FStar.Seq.Base.length iv) 0)) (ensures Vale.Def.Types_s.reverse_bytes_quad32 j0 == Vale.AES.GCM_s.compute_iv_BE h_LE iv)
{ "end_col": 4, "end_line": 147, "start_col": 2, "start_line": 139 }
FStar.Pervasives.Lemma
val gcm_encrypt_LE_fst_helper (iv: supported_iv_LE) (iv_enc iv_BE: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32)) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal ()
val gcm_encrypt_LE_fst_helper (iv: supported_iv_LE) (iv_enc iv_BE: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32)) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) let gcm_encrypt_LE_fst_helper (iv: supported_iv_LE) (iv_enc iv_BE: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32)) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) =
false
null
true
gcm_encrypt_LE_reveal ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.GCM_s.supported_iv_LE", "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Vale.AES.AES_common_s.algorithm", "Vale.Def.Words_s.nat32", "Vale.AES.GCM_s.gcm_encrypt_LE_reveal", "Prims.unit", "Prims.l_and", "Vale.AES.AES_s.is_aes_key_LE", "Prims.eq2", "Vale.AES.GCTR_s.inc32", "Vale.AES.GCM_s.compute_iv_BE", "Vale.Def.Types_s.nat8", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Vale.AES.GCTR.make_gctr_plain_LE", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Def.Words_s.pow2_32", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Prims.squash", "FStar.Pervasives.Native.fst", "Vale.AES.GCM_s.gcm_encrypt_LE", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth))
false
false
Vale.AES.GCM.fst
{ "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" }
null
val gcm_encrypt_LE_fst_helper (iv: supported_iv_LE) (iv_enc iv_BE: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32)) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth))
[]
Vale.AES.GCM.gcm_encrypt_LE_fst_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
iv: Vale.AES.GCM_s.supported_iv_LE -> iv_enc: Vale.Def.Types_s.quad32 -> iv_BE: Vale.Def.Types_s.quad32 -> plain: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ (let h_LE = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in iv_enc == Vale.AES.GCTR_s.inc32 (Vale.AES.GCM_s.compute_iv_BE h_LE iv) 1 /\ cipher == Vale.AES.GCTR_s.gctr_encrypt_LE iv_enc (Vale.AES.GCTR.make_gctr_plain_LE plain) alg key /\ FStar.Seq.Base.length plain < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32)) (ensures cipher == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain auth))
{ "end_col": 26, "end_line": 160, "start_col": 2, "start_line": 160 }
FStar.Pervasives.Lemma
val lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) = gcm_encrypt_LE_reveal (); gcm_decrypt_LE_reveal (); ()
val lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) let lemma_gcm_encrypt_decrypt_equiv (alg: algorithm) (key: seq nat32) (iv: supported_iv_LE) (j0_BE: quad32) (plain cipher auth alleged_tag: seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth)) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) =
false
null
true
gcm_encrypt_LE_reveal (); gcm_decrypt_LE_reveal (); ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.AES.GCM_s.supported_iv_LE", "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat8", "Prims.unit", "Vale.AES.GCM_s.gcm_decrypt_LE_reveal", "Vale.AES.GCM_s.gcm_encrypt_LE_reveal", "Prims.l_and", "Vale.AES.AES_s.is_aes_key_LE", "Prims.b2t", "Prims.op_Equality", "Vale.AES.GCM_s.compute_iv_BE", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Def.Words_s.pow2_32", "Prims.eq2", "Vale.Def.Types_s.nat8", "FStar.Pervasives.Native.fst", "Vale.AES.GCM_s.gcm_encrypt_LE", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "Prims.squash", "Prims.bool", "Vale.AES.GCM_s.gcm_decrypt_LE", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); () // TODO: remove duplicate code -- there is an identical copy of this in GCTR.fst 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; }; () ) #reset-options "--z3rlimit 10" let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) = gcm_blocks_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; () let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag))
false
false
Vale.AES.GCM.fst
{ "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag))
[]
Vale.AES.GCM.lemma_gcm_encrypt_decrypt_equiv
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> plain: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> alleged_tag: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ (let h_LE = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in j0_BE = Vale.AES.GCM_s.compute_iv_BE h_LE iv) /\ FStar.Seq.Base.length cipher < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32 /\ plain == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv cipher auth)) (ensures plain == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_decrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag))
{ "end_col": 4, "end_line": 728, "start_col": 2, "start_line": 726 }
FStar.Pervasives.Lemma
val lemma_le_bytes_to_quad32_prefix_equality (b0: seq nat8 {length b0 == 16}) (b1: seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1))
[ { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i))
val lemma_le_bytes_to_quad32_prefix_equality (b0: seq nat8 {length b0 == 16}) (b1: seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) let lemma_le_bytes_to_quad32_prefix_equality (b0: seq nat8 {length b0 == 16}) (b1: seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) =
false
null
true
let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i: int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i))
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Prims.eq2", "Prims.int", "FStar.Seq.Base.length", "Prims._assert", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Seq.Base.index", "FStar.Seq.Base.slice", "Prims.unit", "FStar.Pervasives.reveal_opaque", "Prims.op_Modulus", "Vale.Def.Words_s.four", "Prims.op_Division", "Vale.Def.Words.Seq_s.seq_to_seq_four_LE", "Vale.Def.Types_s.le_bytes_to_quad32_reveal", "Vale.Def.Types_s.quad32", "Vale.Def.Types_s.le_bytes_to_quad32", "Prims.squash", "Vale.AES.GCM.lower3_equal", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12)
false
false
Vale.AES.GCM.fst
{ "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" }
null
val lemma_le_bytes_to_quad32_prefix_equality (b0: seq nat8 {length b0 == 16}) (b1: seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1))
[]
Vale.AES.GCM.lemma_le_bytes_to_quad32_prefix_equality
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
b0: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length b0 == 16} -> b1: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length b1 == 16} -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.slice b0 0 12 == FStar.Seq.Base.slice b1 0 12) (ensures Vale.AES.GCM.lower3_equal (Vale.Def.Types_s.le_bytes_to_quad32 b0) (Vale.Def.Types_s.le_bytes_to_quad32 b1))
{ "end_col": 80, "end_line": 48, "start_col": 3, "start_line": 37 }
FStar.Pervasives.Lemma
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)
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
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; }; () )
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) =
false
null
true
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": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "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.AES.GCM.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" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); () // TODO: remove duplicate code -- there is an identical copy of this in GCTR.fst 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)
false
false
Vale.AES.GCM.fst
{ "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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
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)
[]
Vale.AES.GCM.lemma_length_simplifier
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
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)
{ "end_col": 3, "end_line": 611, "start_col": 2, "start_line": 598 }
FStar.Pervasives.Lemma
val gcm_encrypt_LE_snd_helper (iv: supported_iv_LE) (j0_BE length_quad32 hash mac: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key))) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal ()
val gcm_encrypt_LE_snd_helper (iv: supported_iv_LE) (j0_BE length_quad32 hash mac: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key))) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) let gcm_encrypt_LE_snd_helper (iv: supported_iv_LE) (j0_BE length_quad32 hash mac: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key))) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) =
false
null
true
insert_nat64_reveal (); gcm_encrypt_LE_reveal ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.GCM_s.supported_iv_LE", "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Vale.AES.AES_common_s.algorithm", "Vale.Def.Words_s.nat32", "Vale.AES.GCM_s.gcm_encrypt_LE_reveal", "Prims.unit", "Vale.Def.Types_s.insert_nat64_reveal", "Prims.l_and", "Vale.AES.AES_s.is_aes_key_LE", "Prims.b2t", "Prims.op_Equality", "Vale.AES.GCM_s.compute_iv_BE", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Def.Words_s.pow2_32", "Prims.eq2", "Vale.Def.Types_s.nat8", "FStar.Pervasives.Native.fst", "Vale.AES.GCM_s.gcm_encrypt_LE", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Types_s.insert_nat64", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "FStar.Mul.op_Star", "Vale.AES.GHash_s.ghash_LE", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "Vale.AES.AES_s.aes_encrypt_LE", "Prims.squash", "FStar.Pervasives.Native.snd", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth))
false
false
Vale.AES.GCM.fst
{ "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" }
null
val gcm_encrypt_LE_snd_helper (iv: supported_iv_LE) (j0_BE length_quad32 hash mac: quad32) (plain auth cipher: seq nat8) (alg: algorithm) (key: seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key))) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth))
[]
Vale.AES.GCM.gcm_encrypt_LE_snd_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> length_quad32: Vale.Def.Types_s.quad32 -> hash: Vale.Def.Types_s.quad32 -> mac: Vale.Def.Types_s.quad32 -> plain: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_s.is_aes_key_LE alg key /\ (let h_LE = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in j0_BE = Vale.AES.GCM_s.compute_iv_BE h_LE iv /\ FStar.Seq.Base.length plain < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32 /\ cipher == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour 0 0 0 0) (8 * FStar.Seq.Base.length auth) 1) (8 * FStar.Seq.Base.length plain) 0) /\ (let auth_padded_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.AES.GCTR_s.pad_to_128_bits auth) in let cipher_padded_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.AES.GCTR_s.pad_to_128_bits cipher) in hash == Vale.AES.GHash_s.ghash_LE h_LE (FStar.Seq.Base.append auth_padded_quads (FStar.Seq.Base.append cipher_padded_quads (FStar.Seq.Base.create 1 length_quad32) )) /\ Vale.Def.Types_s.le_quad32_to_bytes mac == Vale.AES.GCTR_s.gctr_encrypt_LE j0_BE (Vale.Def.Types_s.le_quad32_to_bytes hash) alg key ))) (ensures Vale.Def.Types_s.le_quad32_to_bytes mac == FStar.Pervasives.Native.snd (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain auth))
{ "end_col": 26, "end_line": 198, "start_col": 2, "start_line": 197 }
FStar.Pervasives.Lemma
val decrypt_helper (alg:algorithm) (key:seq nat8) (iv:supported_iv_LE) (cipher:seq nat8) (auth:seq nat8) (rax:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ (if alleged_tag_quad = computed_tag then rax = 0 else rax > 0) /\ le_quad32_to_bytes computed_tag == gcm_decrypt_LE_tag alg key iv cipher auth ) (ensures (rax = 0) == snd (gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad)))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let decrypt_helper (alg:algorithm) (key:seq nat8) (iv:supported_iv_LE) (cipher:seq nat8) (auth:seq nat8) (rax:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ (if alleged_tag_quad = computed_tag then rax = 0 else rax > 0) /\ le_quad32_to_bytes computed_tag == gcm_decrypt_LE_tag alg key iv cipher auth ) (ensures (rax = 0) == snd (gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad))) = gcm_decrypt_LE_reveal (); insert_nat64_reveal (); (* let b = snd (gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad)) in let (_, ct) = gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad) in assert (b = (ct = (le_quad32_to_bytes alleged_tag_quad))); assert (ct == le_quad32_to_bytes computed_tag); assert (b == (le_quad32_to_bytes computed_tag = le_quad32_to_bytes alleged_tag_quad)); *) le_quad32_to_bytes_injective_specific alleged_tag_quad computed_tag; (* assert (b == (computed_tag = alleged_tag_quad)); assert ((rax = 0) == (computed_tag = alleged_tag_quad)); *) ()
val decrypt_helper (alg:algorithm) (key:seq nat8) (iv:supported_iv_LE) (cipher:seq nat8) (auth:seq nat8) (rax:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ (if alleged_tag_quad = computed_tag then rax = 0 else rax > 0) /\ le_quad32_to_bytes computed_tag == gcm_decrypt_LE_tag alg key iv cipher auth ) (ensures (rax = 0) == snd (gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad))) let decrypt_helper (alg: algorithm) (key: seq nat8) (iv: supported_iv_LE) (cipher auth: seq nat8) (rax: nat64) (alleged_tag_quad computed_tag: quad32) : Lemma (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ (if alleged_tag_quad = computed_tag then rax = 0 else rax > 0) /\ le_quad32_to_bytes computed_tag == gcm_decrypt_LE_tag alg key iv cipher auth) (ensures (rax = 0) == snd (gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad))) =
false
null
true
gcm_decrypt_LE_reveal (); insert_nat64_reveal (); le_quad32_to_bytes_injective_specific alleged_tag_quad computed_tag; ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Vale.AES.GCM_s.supported_iv_LE", "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.quad32", "Prims.unit", "Vale.Arch.Types.le_quad32_to_bytes_injective_specific", "Vale.Def.Types_s.insert_nat64_reveal", "Vale.AES.GCM_s.gcm_decrypt_LE_reveal", "Prims.l_and", "Vale.AES.AES_common_s.is_aes_key", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Def.Words_s.pow2_32", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_GreaterThan", "Prims.logical", "Prims.eq2", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.AES.GCM.gcm_decrypt_LE_tag", "Prims.squash", "FStar.Pervasives.Native.snd", "Vale.Def.Types_s.nat8", "Vale.AES.GCM_s.gcm_decrypt_LE", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); () // TODO: remove duplicate code -- there is an identical copy of this in GCTR.fst 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; }; () ) #reset-options "--z3rlimit 10" let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) = gcm_blocks_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; () let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) = gcm_encrypt_LE_reveal (); gcm_decrypt_LE_reveal (); () let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag))) = gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_bytes p_num_bytes iv j0_BE; let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)); lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag; () #reset-options "--z3rlimit 60" let gcm_blocks_dec_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) = insert_nat64_reveal (); let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in //gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes j0_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append p128x6 p128) p_bytes in calc (==) { append (append (append auth_quads p128x6) p128) p_bytes; == { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) p_bytes; == { append_assoc auth_quads (append p128x6 p128) p_bytes } append auth_quads (append (append p128x6 p128) p_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads p128x6) p128) p_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append p128x6 p128) p_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == { assert(equal (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes) plain_bytes) } append (le_seq_quad32_to_bytes auth_quads) plain_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) plain_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) plain_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; () ) else ( calc (==) { append (append (append auth_quads p128x6) p128) (create 1 length_quad); == { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) (create 1 length_quad); == { append_assoc auth_quads (append p128x6 p128) (create 1 length_quad) } append auth_quads (append (append p128x6 p128) (create 1 length_quad)); }; let c = append p128x6 p128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; () ); () #reset-options "" let gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures(let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) = gcm_blocks_dec_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; () let decrypt_helper (alg:algorithm) (key:seq nat8) (iv:supported_iv_LE) (cipher:seq nat8) (auth:seq nat8) (rax:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ (if alleged_tag_quad = computed_tag then rax = 0 else rax > 0) /\ le_quad32_to_bytes computed_tag == gcm_decrypt_LE_tag alg key iv cipher auth ) (ensures (rax = 0) == snd (gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad)))
false
false
Vale.AES.GCM.fst
{ "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" }
null
val decrypt_helper (alg:algorithm) (key:seq nat8) (iv:supported_iv_LE) (cipher:seq nat8) (auth:seq nat8) (rax:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma (requires is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ (if alleged_tag_quad = computed_tag then rax = 0 else rax > 0) /\ le_quad32_to_bytes computed_tag == gcm_decrypt_LE_tag alg key iv cipher auth ) (ensures (rax = 0) == snd (gcm_decrypt_LE alg key iv cipher auth (le_quad32_to_bytes alleged_tag_quad)))
[]
Vale.AES.GCM.decrypt_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> iv: Vale.AES.GCM_s.supported_iv_LE -> cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> rax: Vale.Def.Words_s.nat64 -> alleged_tag_quad: Vale.Def.Types_s.quad32 -> computed_tag: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires Vale.AES.AES_common_s.is_aes_key alg key /\ FStar.Seq.Base.length cipher < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32 /\ (match alleged_tag_quad = computed_tag with | true -> rax = 0 | _ -> rax > 0) /\ Vale.Def.Types_s.le_quad32_to_bytes computed_tag == Vale.AES.GCM.gcm_decrypt_LE_tag alg key iv cipher auth) (ensures rax = 0 == FStar.Pervasives.Native.snd (Vale.AES.GCM_s.gcm_decrypt_LE alg key iv cipher auth (Vale.Def.Types_s.le_quad32_to_bytes alleged_tag_quad)))
{ "end_col": 4, "end_line": 1174, "start_col": 2, "start_line": 1159 }
FStar.Pervasives.Lemma
val gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag)))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag))) = gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_bytes p_num_bytes iv j0_BE; let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)); lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag; ()
val gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag))) let gcm_blocks_helper_dec_simplified (alg: algorithm) (key: seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (auth_bytes alleged_tag: seq nat8) (p_num_bytes: nat) (iv: supported_iv_LE) (j0_BE: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2)) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag))) =
false
null
true
gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_bytes p_num_bytes iv j0_BE; let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)); lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag; ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat8", "Prims.nat", "Vale.AES.GCM_s.supported_iv_LE", "Prims.unit", "Vale.AES.GCM.lemma_gcm_encrypt_decrypt_equiv", "Prims._assert", "Prims.eq2", "Vale.Def.Types_s.nat8", "FStar.Pervasives.Native.fst", "Vale.AES.GCM_s.gcm_encrypt_LE", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "FStar.Seq.Base.slice", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "FStar.Seq.Base.append", "Vale.AES.GCM.lemma_length_simplifier", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Seq.Base.length", "Prims.bool", "Vale.AES.GCM.gcm_blocks_helper_enc", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.int", "Vale.Def.Words_s.pow2_32", "Vale.AES.AES_s.is_aes_key_LE", "Prims.op_Equality", "Vale.AES.GCM_s.compute_iv_BE", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.AES.GCTR.gctr_partial", "Vale.AES.GCTR_s.inc32", "Prims.squash", "Vale.AES.GCM_s.gcm_decrypt_LE", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); () // TODO: remove duplicate code -- there is an identical copy of this in GCTR.fst 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; }; () ) #reset-options "--z3rlimit 10" let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) = gcm_blocks_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; () let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) = gcm_encrypt_LE_reveal (); gcm_decrypt_LE_reveal (); () let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag)))
false
false
Vale.AES.GCM.fst
{ "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag)))
[]
Vale.AES.GCM.gcm_blocks_helper_dec_simplified
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> p128x6: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c128x6: 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 -> auth_bytes: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> alleged_tag: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> p_num_bytes: Prims.nat -> iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\ p_num_bytes < FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 + 16 /\ FStar.Seq.Base.length p128x6 == FStar.Seq.Base.length c128x6 /\ FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\ FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\ FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ (let h_LE = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in j0_BE = Vale.AES.GCM_s.compute_iv_BE h_LE iv) /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\ (let ctr_BE_2 = Vale.AES.GCTR_s.inc32 j0_BE 1 in let plain = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bound = FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128 + (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> 1 | _ -> 0) in Vale.AES.GCTR.gctr_partial alg cipher_bound plain cipher key ctr_BE_2)) (ensures (let plain_raw_quads = FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 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 (FStar.Seq.Base.append c128x6 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 FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\ cipher_bytes == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_decrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag)))
{ "end_col": 4, "end_line": 798, "start_col": 2, "start_line": 778 }
FStar.Pervasives.Lemma
val gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) )
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) = gcm_blocks_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; ()
val gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) let gcm_blocks_helper_simplified (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) =
false
null
true
gcm_blocks_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.AES.GCM_s.supported_iv_LE", "Prims.unit", "Vale.AES.GCM.lemma_length_simplifier", "FStar.Seq.Base.append", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Seq.Base.length", "Prims.bool", "Vale.AES.GCM.gcm_blocks_helper", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Prims.eq2", "Prims.int", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.GCM_s.compute_iv_BE", "Prims.op_Equality", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Types_s.insert_nat64", "Vale.AES.GCTR.gctr_partial", "Vale.AES.GCTR_s.gctr_encrypt_block", "Vale.AES.GHash_s.ghash_LE", "FStar.Seq.Base.create", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.Def.Words_s.nat8", "Vale.AES.GCTR_s.pad_to_128_bits", "FStar.Seq.Base.slice", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.AES.GCTR_s.inc32", "Prims.squash", "FStar.Pervasives.Native.fst", "Vale.AES.GCM_s.gcm_encrypt_LE", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "Vale.Def.Types_s.le_quad32_to_bytes", "FStar.Pervasives.Native.snd", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); () // TODO: remove duplicate code -- there is an identical copy of this in GCTR.fst 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; }; () ) #reset-options "--z3rlimit 10" let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) )
false
false
Vale.AES.GCM.fst
{ "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) )
[]
Vale.AES.GCM.gcm_blocks_helper_simplified
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128x6: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c128x6: 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 -> a_num_bytes: Prims.nat -> iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> h: Vale.Def.Types_s.quad32 -> enc_hash: Vale.Def.Types_s.quad32 -> length_quad: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\ p_num_bytes < FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 + 16 /\ FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\ a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length p128x6 == FStar.Seq.Base.length c128x6 /\ FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\ FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\ FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ j0_BE == Vale.AES.GCM_s.compute_iv_BE h iv /\ h = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ length_quad == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1 = j0_BE in let ctr_BE_2 = Vale.AES.GCTR_s.inc32 j0_BE 1 in let plain = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bound = FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128 + (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> 1 | _ -> 0) in Vale.AES.GCTR.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = (match a_num_bytes > FStar.Seq.Base.length a128 * 16 with | true -> FStar.Seq.Base.append a128 a_bytes | _ -> a128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let auth_input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in let auth_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = FStar.Seq.Base.append (FStar.Seq.Base.append auth_quads c128x6) c128 in let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in let raw_quads = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> let raw_quads = FStar.Seq.Base.append raw_quads c_bytes in let input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits input_bytes in Vale.Def.Types_s.le_bytes_to_seq_quad32 input_padded_bytes | _ -> raw_quads) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let final_quads = FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad) in enc_hash == Vale.AES.GCTR_s.gctr_encrypt_block ctr_BE_1 (Vale.AES.GHash_s.ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = FStar.Seq.Base.append a128 a_bytes in let auth_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 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 (FStar.Seq.Base.append c128x6 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 FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\ cipher_bytes == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ Vale.Def.Types_s.le_quad32_to_bytes enc_hash == FStar.Pervasives.Native.snd (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
{ "end_col": 4, "end_line": 712, "start_col": 2, "start_line": 695 }
FStar.Pervasives.Lemma
val gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures(let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures(let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) = gcm_blocks_dec_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; ()
val gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures(let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) let gcm_blocks_dec_helper_simplified (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) =
false
null
true
gcm_blocks_dec_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.AES.GCM_s.supported_iv_LE", "Prims.unit", "Vale.AES.GCM.lemma_length_simplifier", "FStar.Seq.Base.append", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Seq.Base.length", "Prims.bool", "Vale.AES.GCM.gcm_blocks_dec_helper", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Prims.eq2", "Prims.int", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.GCM_s.compute_iv_BE", "Prims.op_Equality", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Types_s.insert_nat64", "Vale.AES.GCTR.gctr_partial", "Vale.AES.GCTR_s.gctr_encrypt_block", "Vale.AES.GHash_s.ghash_LE", "FStar.Seq.Base.create", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.Def.Words_s.nat8", "Vale.AES.GCTR_s.pad_to_128_bits", "FStar.Seq.Base.slice", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.AES.GCTR_s.inc32", "Prims.squash", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.AES.GCM.gcm_decrypt_LE_tag", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); () // TODO: remove duplicate code -- there is an identical copy of this in GCTR.fst 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; }; () ) #reset-options "--z3rlimit 10" let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) = gcm_blocks_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; () let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) = gcm_encrypt_LE_reveal (); gcm_decrypt_LE_reveal (); () let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag))) = gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_bytes p_num_bytes iv j0_BE; let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)); lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag; () #reset-options "--z3rlimit 60" let gcm_blocks_dec_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) = insert_nat64_reveal (); let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in //gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes j0_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append p128x6 p128) p_bytes in calc (==) { append (append (append auth_quads p128x6) p128) p_bytes; == { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) p_bytes; == { append_assoc auth_quads (append p128x6 p128) p_bytes } append auth_quads (append (append p128x6 p128) p_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads p128x6) p128) p_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append p128x6 p128) p_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == { assert(equal (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes) plain_bytes) } append (le_seq_quad32_to_bytes auth_quads) plain_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) plain_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) plain_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; () ) else ( calc (==) { append (append (append auth_quads p128x6) p128) (create 1 length_quad); == { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) (create 1 length_quad); == { append_assoc auth_quads (append p128x6 p128) (create 1 length_quad) } append auth_quads (append (append p128x6 p128) (create 1 length_quad)); }; let c = append p128x6 p128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; () ); () #reset-options "" let gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures(let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
false
false
Vale.AES.GCM.fst
{ "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" }
null
val gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures(let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
[]
Vale.AES.GCM.gcm_blocks_dec_helper_simplified
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128x6: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c128x6: 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 -> a_num_bytes: Prims.nat -> iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> h: Vale.Def.Types_s.quad32 -> enc_hash: Vale.Def.Types_s.quad32 -> length_quad: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\ p_num_bytes < FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 + 16 /\ FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\ a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length p128x6 == FStar.Seq.Base.length c128x6 /\ FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\ FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\ FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ j0_BE == Vale.AES.GCM_s.compute_iv_BE h iv /\ h = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ length_quad == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1 = j0_BE in let ctr_BE_2 = Vale.AES.GCTR_s.inc32 j0_BE 1 in let plain = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bound = FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128 + (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> 1 | _ -> 0) in Vale.AES.GCTR.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = (match a_num_bytes > FStar.Seq.Base.length a128 * 16 with | true -> FStar.Seq.Base.append a128 a_bytes | _ -> a128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let auth_input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in let auth_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = FStar.Seq.Base.append (FStar.Seq.Base.append auth_quads p128x6) p128 in let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in let raw_quads = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> let raw_quads = FStar.Seq.Base.append raw_quads p_bytes in let input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits input_bytes in Vale.Def.Types_s.le_bytes_to_seq_quad32 input_padded_bytes | _ -> raw_quads) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let final_quads = FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad) in enc_hash == Vale.AES.GCTR_s.gctr_encrypt_block ctr_BE_1 (Vale.AES.GHash_s.ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = FStar.Seq.Base.append a128 a_bytes in let auth_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 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 (FStar.Seq.Base.append c128x6 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 FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\ Vale.Def.Types_s.le_quad32_to_bytes enc_hash == Vale.AES.GCM.gcm_decrypt_LE_tag alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
{ "end_col": 4, "end_line": 1145, "start_col": 2, "start_line": 1128 }
FStar.Pervasives.Lemma
val gcm_blocks_helper_enc (alg: algorithm) (key: seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (auth_bytes: seq nat8) (p_num_bytes: nat) (iv: supported_iv_LE) (j0_BE: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; ()
val gcm_blocks_helper_enc (alg: algorithm) (key: seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (auth_bytes: seq nat8) (p_num_bytes: nat) (iv: supported_iv_LE) (j0_BE: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) let gcm_blocks_helper_enc (alg: algorithm) (key: seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (auth_bytes: seq nat8) (p_num_bytes: nat) (iv: supported_iv_LE) (j0_BE: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) =
false
null
true
let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then (gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert (index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert (gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) else (gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.nat8", "Prims.nat", "Vale.AES.GCM_s.supported_iv_LE", "Prims.unit", "Vale.AES.GCM.gcm_encrypt_LE_fst_helper", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Seq.Base.length", "Prims._assert", "Prims.eq2", "Vale.Def.Types_s.nat8", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Vale.AES.GCTR.gctr_partial_to_full_advanced", "Vale.AES.AES_s.aes_encrypt_LE_reveal", "Vale.AES.GCTR_s.gctr_encrypt_block", "FStar.Seq.Base.index", "Vale.AES.GCTR_s.inc32", "Vale.AES.GCTR.gctr_encrypt_block_offset", "Vale.Def.Types_s.quad32_xor", "Vale.AES.GCTR.aes_encrypt_BE", "Prims.int", "Prims.op_Division", "Vale.AES.GCTR.gctr_partial_opaque_completed", "FStar.Seq.Base.append", "Vale.AES.GCTR.gctr_partial", "Vale.AES.GCTR.gctr_partial_opaque_ignores_postfix", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Vale.AES.GCTR.gctr_partial_reveal", "Prims.bool", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.AES.GCTR.gctr_partial_to_full_basic", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Vale.AES.AES_s.is_aes_key_LE", "Prims.op_Equality", "Vale.AES.GCM_s.compute_iv_BE", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Prims.squash", "FStar.Pervasives.Native.fst", "Vale.AES.GCM_s.gcm_encrypt_LE", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key))
false
false
Vale.AES.GCM.fst
{ "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gcm_blocks_helper_enc (alg: algorithm) (key: seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (auth_bytes: seq nat8) (p_num_bytes: nat) (iv: supported_iv_LE) (j0_BE: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
[]
Vale.AES.GCM.gcm_blocks_helper_enc
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> p128x6: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c128x6: 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 -> auth_bytes: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> p_num_bytes: Prims.nat -> iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\ p_num_bytes < FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 + 16 /\ FStar.Seq.Base.length p128x6 == FStar.Seq.Base.length c128x6 /\ FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\ FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\ FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ (let h_LE = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in j0_BE = Vale.AES.GCM_s.compute_iv_BE h_LE iv /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\ (let ctr_BE_2 = Vale.AES.GCTR_s.inc32 j0_BE 1 in let plain = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bound = FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128 + (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> 1 | _ -> 0) in Vale.AES.GCTR.gctr_partial alg cipher_bound plain cipher key ctr_BE_2))) (ensures (let plain = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let ctr_BE_2 = Vale.AES.GCTR_s.inc32 j0_BE 1 in let plain_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes cipher) 0 p_num_bytes in cipher_bytes == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
{ "end_col": 4, "end_line": 311, "start_col": 3, "start_line": 259 }
FStar.Pervasives.Lemma
val lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv)
[ { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; ()
val lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) let lemma_compute_iv_easy (iv_b iv_extra_b: seq quad32) (iv: supported_iv_LE) (num_bytes: nat64) (h_LE j0: quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128 / 8) <= num_bytes /\ num_bytes < length iv_b * (128 / 8) + 128 / 8 /\ num_bytes == 96 / 8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) =
false
null
true
assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); calc ( == ) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; ( == ) { () } slice (pad_to_128_bits iv) 0 12; }; calc ( == ) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); ( == ) { () } le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); ( == ) { () } le_bytes_to_quad32 (pad_to_128_bits iv); }; calc ( == ) { j0; ( == ) { () } set_to_one_LE (reverse_bytes_quad32 q); ( == ) { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); ( == ) { (lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); ( == ) { (lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv)) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); ( == ) { compute_iv_BE_reveal () } compute_iv_BE h_LE iv; }; ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Vale.AES.GCM_s.supported_iv_LE", "Vale.Def.Words_s.nat64", "Prims.unit", "FStar.Calc.calc_finish", "Prims.eq2", "Vale.AES.GCM_s.compute_iv_BE", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Vale.AES.GCM.set_to_one_LE", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Types_s.le_bytes_to_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "FStar.Seq.Base.slice", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.le_quad32_to_bytes", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Vale.Arch.Types.le_bytes_to_quad32_to_bytes", "Vale.AES.GCM.lemma_set_to_one_reverse_equality", "Vale.AES.GCM.lemma_le_bytes_to_quad32_prefix_equality", "Vale.AES.GCM.lemma_le_seq_quad32_to_bytes_prefix_equality", "Vale.AES.GCM_s.compute_iv_BE_reveal", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.create", "Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton", "FStar.Seq.Base.index", "FStar.Seq.Base.append", "FStar.Seq.Base.append_empty_l", "FStar.Seq.Base.lemma_empty", "Prims.int", "FStar.Seq.Base.length", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.op_LessThan", "Prims.op_Addition", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.__proj__Mkfour__item__hi2", "Vale.Def.Words_s.__proj__Mkfour__item__hi3", "Vale.Def.Words_s.nat8", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv)
false
false
Vale.AES.GCM.fst
{ "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" }
null
val lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv)
[]
Vale.AES.GCM.lemma_compute_iv_easy
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
iv_b: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> iv_extra_b: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> iv: Vale.AES.GCM_s.supported_iv_LE -> num_bytes: Vale.Def.Words_s.nat64 -> h_LE: Vale.Def.Types_s.quad32 -> j0: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length iv_extra_b == 1 /\ FStar.Seq.Base.length iv_b * (128 / 8) <= num_bytes /\ num_bytes < FStar.Seq.Base.length iv_b * (128 / 8) + 128 / 8 /\ num_bytes == 96 / 8 /\ (let iv_BE = Vale.Def.Types_s.reverse_bytes_quad32 (FStar.Seq.Base.index iv_extra_b 0) in j0 == Vale.Def.Words_s.Mkfour 1 (Mkfour?.lo1 iv_BE) (Mkfour?.hi2 iv_BE) (Mkfour?.hi3 iv_BE)) /\ (let raw_quads = FStar.Seq.Base.append iv_b iv_extra_b in let iv_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == Vale.AES.GCM_s.compute_iv_BE h_LE iv)
{ "end_col": 4, "end_line": 121, "start_col": 2, "start_line": 69 }
FStar.Pervasives.Lemma
val gcm_blocks_dec_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_blocks_dec_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) = insert_nat64_reveal (); let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in //gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes j0_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append p128x6 p128) p_bytes in calc (==) { append (append (append auth_quads p128x6) p128) p_bytes; == { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) p_bytes; == { append_assoc auth_quads (append p128x6 p128) p_bytes } append auth_quads (append (append p128x6 p128) p_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads p128x6) p128) p_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append p128x6 p128) p_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == { assert(equal (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes) plain_bytes) } append (le_seq_quad32_to_bytes auth_quads) plain_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) plain_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) plain_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; () ) else ( calc (==) { append (append (append auth_quads p128x6) p128) (create 1 length_quad); == { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) (create 1 length_quad); == { append_assoc auth_quads (append p128x6 p128) (create 1 length_quad) } append auth_quads (append (append p128x6 p128) (create 1 length_quad)); }; let c = append p128x6 p128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; () ); ()
val gcm_blocks_dec_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) let gcm_blocks_dec_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) =
false
null
true
insert_nat64_reveal (); let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in calc ( == ) { enc_hash; ( == ) { () } gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; ( == ) { () } gctr_encrypt_block ctr_BE_1 hash alg key 0; ( == ) { () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); ( == ) { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); ( == ) { () } quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc ( == ) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; ( == ) { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); ( == ) { () } le_seq_quad32_to_bytes (create 1 enc_hash); ( == ) { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then (let c = append (append p128x6 p128) p_bytes in calc ( == ) { append (append (append auth_quads p128x6) p128) p_bytes; ( == ) { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) p_bytes; ( == ) { append_assoc auth_quads (append p128x6 p128) p_bytes } append auth_quads (append (append p128x6 p128) p_bytes); ( == ) { () } append auth_quads c; }; calc ( == ) { append (append (append (append auth_quads p128x6) p128) p_bytes) (create 1 length_quad); ( = ) { () } append (append auth_quads (append (append p128x6 p128) p_bytes)) (create 1 length_quad); ( == ) { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc ( == ) { raw_quads; ( == ) { () } le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); ( == ) { calc ( == ) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); ( == ) { calc ( == ) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; ( == ) { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; ( == ) { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); ( == ) { assert (equal (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes) plain_bytes) } append (le_seq_quad32_to_bytes auth_quads) plain_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) plain_bytes); ( == ) { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) plain_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes)); ( == ) { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits plain_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); ( == ) { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in calc ( == ) { append raw_quads (create 1 length_quad); ( == ) { () } append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes))) (create 1 length_quad); ( == ) { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); ( == ) { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; ()) else (calc ( == ) { append (append (append auth_quads p128x6) p128) (create 1 length_quad); ( == ) { append_assoc auth_quads p128x6 p128 } append (append auth_quads (append p128x6 p128)) (create 1 length_quad); ( == ) { append_assoc auth_quads (append p128x6 p128) (create 1 length_quad) } append auth_quads (append (append p128x6 p128) (create 1 length_quad)); }; let c = append p128x6 p128 in calc ( == ) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); ( == ) { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); ( == ) { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); ( == ) { le_bytes_to_seq_quad32_to_bytes c } c; }; ()); ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.AES.GCM_s.supported_iv_LE", "Prims.unit", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Seq.Base.length", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.append_assoc", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.slice", "Vale.AES.GCM.append_distributes_le_seq_quad32_to_bytes", "Vale.AES.GCM.slice_append_back", "Vale.AES.GCM.pad_to_128_bits_multiple_append", "Vale.Arch.Types.append_distributes_le_bytes_to_seq_quad32", "Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.Def.Types_s.quad32_xor", "Vale.AES.GCTR.aes_encrypt_BE", "Vale.AES.GCTR.gctr_encrypt_one_block", "Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.AES.GCTR_s.gctr_encrypt_block", "Vale.AES.GHash_s.ghash_LE", "Vale.AES.AES_s.aes_encrypt_LE_reveal", "Vale.Def.Words_s.nat8", "Prims.int", "Vale.AES.GCTR_s.inc32", "Vale.Def.Types_s.insert_nat64_reveal", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.GCM_s.compute_iv_BE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.insert_nat64", "Vale.AES.GCTR.gctr_partial", "Vale.AES.GCM.gcm_decrypt_LE_tag", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); () // TODO: remove duplicate code -- there is an identical copy of this in GCTR.fst 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; }; () ) #reset-options "--z3rlimit 10" let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = append a128 a_bytes in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)) ) = gcm_blocks_helper alg key a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad; let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes; lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; () let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_LE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\ plain == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth) ) (ensures plain == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv cipher auth alleged_tag)) = gcm_encrypt_LE_reveal (); gcm_decrypt_LE_reveal (); () let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes alleged_tag:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 )) (ensures (let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_decrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes alleged_tag))) = gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_bytes p_num_bytes iv j0_BE; let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher_raw_quads:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in lemma_length_simplifier (append p128x6 p128) p_bytes plain_raw_quads p_num_bytes; lemma_length_simplifier (append c128x6 c128) c_bytes cipher_raw_quads p_num_bytes; let plain_raw_quads = append (append p128x6 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 (append c128x6 c128) c_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher_raw_quads) 0 p_num_bytes in assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)); lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag; () #reset-options "--z3rlimit 60" let gcm_blocks_dec_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
false
false
Vale.AES.GCM.fst
{ "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": 60, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gcm_blocks_dec_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads p128x6) p128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads p_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ le_quad32_to_bytes enc_hash == gcm_decrypt_LE_tag alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
[]
Vale.AES.GCM.gcm_blocks_dec_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128x6: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c128x6: 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 -> a_num_bytes: Prims.nat -> iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> h: Vale.Def.Types_s.quad32 -> enc_hash: Vale.Def.Types_s.quad32 -> length_quad: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\ p_num_bytes < FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 + 16 /\ FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\ a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length p128x6 == FStar.Seq.Base.length c128x6 /\ FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\ FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\ FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ j0_BE = Vale.AES.GCM_s.compute_iv_BE h iv /\ h = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ length_quad == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1 = j0_BE in let ctr_BE_2 = Vale.AES.GCTR_s.inc32 j0_BE 1 in let plain = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bound = FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128 + (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> 1 | _ -> 0) in Vale.AES.GCTR.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = (match a_num_bytes > FStar.Seq.Base.length a128 * 16 with | true -> FStar.Seq.Base.append a128 a_bytes | _ -> a128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let auth_input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in let auth_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = FStar.Seq.Base.append (FStar.Seq.Base.append auth_quads p128x6) p128 in let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in let raw_quads = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> let raw_quads = FStar.Seq.Base.append raw_quads p_bytes in let input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits input_bytes in Vale.Def.Types_s.le_bytes_to_seq_quad32 input_padded_bytes | _ -> raw_quads) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let final_quads = FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad) in enc_hash == Vale.AES.GCTR_s.gctr_encrypt_block ctr_BE_1 (Vale.AES.GHash_s.ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = (match a_num_bytes > FStar.Seq.Base.length a128 * 16 with | true -> FStar.Seq.Base.append a128 a_bytes | _ -> a128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let auth_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 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 = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes cipher) 0 p_num_bytes in FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\ Vale.Def.Types_s.le_quad32_to_bytes enc_hash == Vale.AES.GCM.gcm_decrypt_LE_tag alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))
{ "end_col": 4, "end_line": 1047, "start_col": 2, "start_line": 890 }
FStar.Pervasives.Lemma
val gcm_blocks_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
[ { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "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.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCTR_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_helpers", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.AES_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GCM_s", "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.Opaque_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 } ]
false
let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; //assert (cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain_bytes auth_input_bytes)); // Passes calc (==) { enc_hash; == {} gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; == {} gctr_encrypt_block ctr_BE_1 hash alg key 0; == {} quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); == {} quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc (==) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; == { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); == {} le_seq_quad32_to_bytes (create 1 enc_hash); == { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then ( let c = append (append c128x6 c128) c_bytes in calc (==) { append (append (append auth_quads c128x6) c128) c_bytes; == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; == { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); == {} append auth_quads c; }; calc (==) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); = {} // See previous calc append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); == { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc (==) { raw_quads; == {} le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); == { calc (==) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); == { calc (==) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; == { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; == { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); == {} append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); == { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); == { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); == { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc (==) { append raw_quads (create 1 length_quad); == {} append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); == { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); == { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ) else ( calc (==) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); == { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); == { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc (==) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); == { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); == { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); == { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; () ); ()
val gcm_blocks_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) let gcm_blocks_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) =
false
null
true
let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in let hash = ghash_LE h final_quads in gcm_blocks_helper_enc alg key p128x6 p128 p_bytes c128x6 c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE; calc ( == ) { enc_hash; ( == ) { () } gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0; ( == ) { () } gctr_encrypt_block ctr_BE_1 hash alg key 0; ( == ) { () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); ( == ) { aes_encrypt_LE_reveal () } quad32_xor hash (aes_encrypt_LE alg key (reverse_bytes_quad32 ctr_BE_1)); ( == ) { () } quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1); }; calc ( == ) { gctr_encrypt_LE ctr_BE_1 (le_quad32_to_bytes hash) alg key; ( == ) { gctr_encrypt_one_block ctr_BE_1 hash alg key } le_seq_quad32_to_bytes (create 1 (quad32_xor hash (aes_encrypt_BE alg key ctr_BE_1))); ( == ) { () } le_seq_quad32_to_bytes (create 1 enc_hash); ( == ) { le_seq_quad32_to_bytes_of_singleton enc_hash } le_quad32_to_bytes enc_hash; }; if p_num_bytes > (length p128x6 + length p128) * 16 then (let c = append (append c128x6 c128) c_bytes in calc ( == ) { append (append (append auth_quads c128x6) c128) c_bytes; ( == ) { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) c_bytes; ( == ) { append_assoc auth_quads (append c128x6 c128) c_bytes } append auth_quads (append (append c128x6 c128) c_bytes); ( == ) { () } append auth_quads c; }; calc ( == ) { append (append (append (append auth_quads c128x6) c128) c_bytes) (create 1 length_quad); ( = ) { () } append (append auth_quads (append (append c128x6 c128) c_bytes)) (create 1 length_quad); ( == ) { append_assoc auth_quads c (create 1 length_quad) } append auth_quads (append c (create 1 length_quad)); }; let raw_quads_old = append auth_quads c in calc ( == ) { raw_quads; ( == ) { () } le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes)); ( == ) { calc ( == ) { pad_to_128_bits (slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes); ( == ) { calc ( == ) { slice (le_seq_quad32_to_bytes raw_quads_old) 0 total_bytes; ( == ) { append_distributes_le_seq_quad32_to_bytes auth_quads c } slice (append (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c)) 0 total_bytes; ( == ) { slice_append_back (le_seq_quad32_to_bytes auth_quads) (le_seq_quad32_to_bytes c) total_bytes } append (le_seq_quad32_to_bytes auth_quads) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes); ( == ) { () } append (le_seq_quad32_to_bytes auth_quads) cipher_bytes; } } pad_to_128_bits (append (le_seq_quad32_to_bytes auth_quads) cipher_bytes); ( == ) { pad_to_128_bits_multiple_append (le_seq_quad32_to_bytes auth_quads) cipher_bytes } append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes); } } le_bytes_to_seq_quad32 (append (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes)); ( == ) { append_distributes_le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads) (pad_to_128_bits cipher_bytes) } append (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes auth_quads)) (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); ( == ) { le_bytes_to_seq_quad32_to_bytes auth_quads } append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)); }; let auth_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in let cipher_padded_quads' = le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in calc ( == ) { append raw_quads (create 1 length_quad); ( == ) { () } append (append auth_quads (le_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad); ( == ) { assert (equal auth_quads auth_padded_quads') } append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad); ( == ) { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) } append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad)); }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; ()) else (calc ( == ) { append (append (append auth_quads c128x6) c128) (create 1 length_quad); ( == ) { append_assoc auth_quads c128x6 c128 } append (append auth_quads (append c128x6 c128)) (create 1 length_quad); ( == ) { append_assoc auth_quads (append c128x6 c128) (create 1 length_quad) } append auth_quads (append (append c128x6 c128) (create 1 length_quad)); }; let c = append c128x6 c128 in calc ( == ) { le_bytes_to_seq_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)); ( == ) { assert (equal (le_seq_quad32_to_bytes c) (slice (le_seq_quad32_to_bytes c) 0 p_num_bytes)) } le_bytes_to_seq_quad32 (pad_to_128_bits (le_seq_quad32_to_bytes c)); ( == ) { assert (pad_to_128_bits (le_seq_quad32_to_bytes c) == (le_seq_quad32_to_bytes c)) } le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes c); ( == ) { le_bytes_to_seq_quad32_to_bytes c } c; }; insert_nat64_reveal (); gcm_encrypt_LE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key; ()); ()
{ "checked_file": "Vale.AES.GCM.fst.checked", "dependencies": [ "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.Types_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GHash.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCTR.fsti.checked", "Vale.AES.GCM_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "Vale.AES.AES_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Vale.AES.GCM.fst" }
[ "lemma" ]
[ "Vale.AES.AES_common_s.algorithm", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.quad32", "Prims.nat", "Vale.AES.GCM_s.supported_iv_LE", "Prims.unit", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Seq.Base.length", "Vale.AES.GCM.gcm_encrypt_LE_snd_helper", "Vale.Def.Types_s.insert_nat64_reveal", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Vale.Def.Types_s.le_bytes_to_seq_quad32", "Vale.AES.GCTR_s.pad_to_128_bits", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Prims._assert", "FStar.Seq.Base.equal", "FStar.Seq.Base.append_assoc", "Vale.Def.Types_s.le_seq_quad32_to_bytes", "Vale.Def.Types_s.nat8", "FStar.Seq.Base.slice", "Vale.AES.GCM.append_distributes_le_seq_quad32_to_bytes", "Vale.AES.GCM.slice_append_back", "Vale.AES.GCM.pad_to_128_bits_multiple_append", "Vale.Arch.Types.append_distributes_le_bytes_to_seq_quad32", "Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes", "Prims.b2t", "Prims.op_Equality", "Prims.bool", "Vale.AES.GCTR_s.gctr_encrypt_LE", "Vale.Def.Types_s.le_quad32_to_bytes", "Vale.Def.Types_s.quad32_xor", "Vale.AES.GCTR.aes_encrypt_BE", "Vale.AES.GCTR.gctr_encrypt_one_block", "Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton", "Vale.AES.AES_s.aes_encrypt_LE", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.AES.GCTR_s.gctr_encrypt_block", "Vale.AES.GHash_s.ghash_LE", "Vale.AES.AES_s.aes_encrypt_LE_reveal", "Vale.AES.GCM.gcm_blocks_helper_enc", "Vale.Def.Words_s.nat8", "Prims.int", "Vale.AES.GCTR_s.inc32", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Vale.Def.Words_s.pow2_32", "Vale.AES.AES_s.is_aes_key_LE", "Vale.AES.GCM_s.compute_iv_BE", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.insert_nat64", "Vale.AES.GCTR.gctr_partial", "FStar.Pervasives.Native.fst", "Vale.AES.GCM_s.gcm_encrypt_LE", "Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE", "FStar.Pervasives.Native.snd", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GCM open Vale.Def.Opaque_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GCM_s open Vale.AES.AES_s open Vale.AES.GCM_helpers open Vale.AES.GCTR_s open Vale.AES.GCTR open Vale.AES.GHash_s open FStar.Mul open FStar.Seq open Vale.Def.Words_s open Vale.Def.Words.Seq_s open FStar.Calc open Vale.Def.Words.Four_s let lemma_set_to_one_equality (q0 q1:quad32) : Lemma (requires upper3_equal q0 q1) (ensures set_to_one_LE q0 == set_to_one_LE q1) = () let lemma_set_to_one_reverse_equality (q0 q1:quad32) : Lemma (requires lower3_equal q0 q1) (ensures set_to_one_LE (reverse_bytes_quad32 q0) == set_to_one_LE (reverse_bytes_quad32 q1)) = reveal_reverse_bytes_quad32 q0; reveal_reverse_bytes_quad32 q1; () let lemma_le_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma (requires slice b0 0 12 == slice b1 0 12) (ensures lower3_equal (le_bytes_to_quad32 b0) (le_bytes_to_quad32 b1)) = let q0 = le_bytes_to_quad32 b0 in let q1 = le_bytes_to_quad32 b1 in le_bytes_to_quad32_reveal (); (* * AR: 06/25: Someone should review this code, is this proof supposed to work without revealing this? *) reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8); assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) let lemma_le_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma (slice (le_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) = assert (equal (slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12) (slice (le_quad32_to_bytes q) 0 12)); () let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_LE) (num_bytes:nat64) (h_LE j0:quad32) : Lemma (requires length iv_extra_b == 1 /\ length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\ num_bytes == 96/8 /\ (let iv_BE = reverse_bytes_quad32 (index iv_extra_b 0) in j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\ (let raw_quads = append iv_b iv_extra_b in let iv_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 num_bytes in iv_bytes == iv)) (ensures j0 == compute_iv_BE h_LE iv) = assert (length iv == 12); assert (length iv_b == 0); lemma_empty iv_b; append_empty_l iv_extra_b; assert (append iv_b iv_extra_b == iv_extra_b); let q = index iv_extra_b 0 in le_seq_quad32_to_bytes_of_singleton q; assert (equal iv_extra_b (create 1 q)); assert (le_seq_quad32_to_bytes iv_extra_b == le_quad32_to_bytes q); // Prove this so we can call lemma_le_bytes_to_quad32_prefix_equality below calc (==) { slice (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) 0 12; == {} slice (pad_to_128_bits iv) 0 12; }; // Prove this so we can call lemma_set_to_one_reverse_equality below calc (==) { le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits (slice (le_seq_quad32_to_bytes iv_extra_b) 0 num_bytes)); == {} le_bytes_to_quad32 (pad_to_128_bits iv); }; calc (==) { j0; == {} set_to_one_LE (reverse_bytes_quad32 q); == { le_bytes_to_quad32_to_bytes q } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (le_quad32_to_bytes q))); == { lemma_le_seq_quad32_to_bytes_prefix_equality q; lemma_le_bytes_to_quad32_prefix_equality (le_quad32_to_bytes q) (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)); lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (le_quad32_to_bytes q)) (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)))); == { lemma_set_to_one_reverse_equality (le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12))) (le_bytes_to_quad32 (pad_to_128_bits iv)); lemma_le_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 12)) (pad_to_128_bits iv) } set_to_one_LE (reverse_bytes_quad32 (le_bytes_to_quad32 (pad_to_128_bits iv))); == {compute_iv_BE_reveal ()} compute_iv_BE h_LE iv; }; () open Vale.AES.GHash let lemma_compute_iv_hard (iv:supported_iv_LE) (quads:seq quad32) (length_quad h_LE j0:quad32) : Lemma (requires ~(length iv == 96/8) /\ quads == le_bytes_to_seq_quad32 (pad_to_128_bits iv) /\ j0 == ghash_incremental h_LE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) 0 1) (8 * (length iv)) 0)) (ensures reverse_bytes_quad32 j0 == compute_iv_BE h_LE iv) = assert (two_to_nat32 (Mktwo 0 0) == 0); let q0 = Mkfour 0 0 0 0 in lemma_insert_nat64_nat32s q0 0 0; assert (insert_nat64 q0 0 1 == q0); insert_nat64_reveal (); assert (length_quad == reverse_bytes_quad32 (insert_nat64_def (Mkfour 0 0 0 0) (8 * length iv) 0)); ghash_incremental_to_ghash h_LE (append quads (create 1 length_quad)); compute_iv_BE_reveal (); () let gcm_encrypt_LE_fst_helper (iv:supported_iv_LE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in iv_enc == inc32 (compute_iv_BE h_LE iv) 1 /\ cipher == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key /\ length plain < pow2_32 /\ length auth < pow2_32 )) (ensures cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = gcm_encrypt_LE_reveal () (* let s_key_LE = seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE key) in let s_iv_BE = be_bytes_to_quad32 (be_quad32_to_bytes iv_BE) in let s_j0_BE = Mkfour 1 s_iv_BE.lo1 s_iv_BE.hi2 s_iv_BE.hi3 in let s_cipher = fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in be_bytes_to_quad32_to_bytes iv_BE; assert (s_cipher == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE); assert (s_iv_BE == iv_BE); assert (s_key_LE == key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg s_key_LE == gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) plain alg key == gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key); assert (gctr_encrypt_LE (inc32 s_j0_BE 1) (make_gctr_plain_LE plain) alg key == gctr_encrypt_LE iv_enc (make_gctr_plain_LE plain) alg key); () *) let gcm_encrypt_LE_snd_helper (iv:supported_iv_LE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma (requires is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ length plain < pow2_32 /\ length auth < pow2_32 /\ cipher == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth) /\ length_quad32 == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * length auth) 1) (8 * length plain) 0) /\ (let auth_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits auth) in let cipher_padded_quads = le_bytes_to_seq_quad32 (pad_to_128_bits cipher) in hash == ghash_LE h_LE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\ le_quad32_to_bytes mac == gctr_encrypt_LE j0_BE (le_quad32_to_bytes hash) alg key) )) (ensures le_quad32_to_bytes mac == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain auth)) = insert_nat64_reveal (); gcm_encrypt_LE_reveal () //be_bytes_to_quad32_to_bytes iv_BE; //let t = snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) (be_quad32_to_bytes iv_BE) plain auth) in //() #reset-options "--z3rlimit 10" let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32) (p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (auth_bytes:seq nat8) (p_num_bytes:nat) (iv:supported_iv_LE) (j0_BE:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ (length auth_bytes) < pow2_32 /\ is_aes_key_LE alg key /\ (let h_LE = aes_encrypt_LE alg key (Mkfour 0 0 0 0) in j0_BE = compute_iv_BE h_LE iv /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ (let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 ))) (ensures (let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in //cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key)) cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes))) = let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in gctr_partial_opaque_completed alg plain cipher key ctr_BE_2; if p_num_bytes > (length p128x6 + length p128) * 16 then ( gctr_partial_reveal (); assert (gctr_partial alg (length p128x6 + length p128) plain cipher key ctr_BE_2); assert (equal (slice plain 0 (length p128x6 + length p128)) (slice (append p128x6 p128) 0 (length p128x6 + length p128))); assert (equal (slice cipher 0 (length p128x6 + length p128)) (slice (append c128x6 c128) 0 (length p128x6 + length p128))); gctr_partial_opaque_ignores_postfix alg (length p128x6 + length p128) plain (append p128x6 p128) cipher (append c128x6 c128) key ctr_BE_2; assert (gctr_partial alg (length p128x6 + length p128) (append p128x6 p128) (append c128x6 c128) key ctr_BE_2); gctr_partial_opaque_completed alg (append p128x6 p128) (append c128x6 c128) key ctr_BE_2; let num_blocks = p_num_bytes / 16 in assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_BE alg key (inc32 ctr_BE_2 num_blocks))); gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks; assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks == gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0); aes_encrypt_LE_reveal (); gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes; assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ) else ( gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher; assert (le_seq_quad32_to_bytes cipher == gctr_encrypt_LE ctr_BE_2 (le_seq_quad32_to_bytes plain) alg key); let plain_bytes = slice (le_seq_quad32_to_bytes plain) 0 p_num_bytes in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in assert (equal plain_bytes (le_seq_quad32_to_bytes plain)); assert (equal cipher_bytes (le_seq_quad32_to_bytes cipher)); assert (cipher_bytes == gctr_encrypt_LE ctr_BE_2 plain_bytes alg key) ); gcm_encrypt_LE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key; () let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma (requires length x <= i /\ i <= length x + length y) (ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) = assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x)))); () let append_distributes_le_seq_quad32_to_bytes (x y:seq quad32) : Lemma (le_seq_quad32_to_bytes (append x y) == append (le_seq_quad32_to_bytes x) (le_seq_quad32_to_bytes y)) = append_distributes_le_seq_quad32_to_bytes x y let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma (requires length x % 16 == 0) (ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) = assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) #reset-options "--z3rlimit 100" let gcm_blocks_helper (alg:algorithm) (key:seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes:seq quad32) (p_num_bytes a_num_bytes:nat) (iv:supported_iv_LE) (j0_BE h enc_hash length_quad:quad32) : Lemma (requires // Required by gcm_blocks length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ // Ensured by gcm_blocks p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0 ))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key)
false
false
Vale.AES.GCM.fst
{ "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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gcm_blocks_helper (alg: algorithm) (key: seq nat32) (a128 a_bytes p128x6 p128 p_bytes c128x6 c128 c_bytes: seq quad32) (p_num_bytes a_num_bytes: nat) (iv: supported_iv_LE) (j0_BE h enc_hash length_quad: quad32) : Lemma (requires length p128x6 * 16 + length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128x6 * 16 + length p128 * 16 + 16 /\ length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\ a_num_bytes < pow2_32 /\ length p128x6 == length c128x6 /\ length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_LE alg key /\ j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_LE alg key (Mkfour 0 0 0 0) /\ p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\ length_quad == reverse_bytes_quad32 (insert_nat64 (insert_nat64 (Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1:quad32 = j0_BE in let ctr_BE_2:quad32 = inc32 j0_BE 1 in let plain:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bound:nat = length p128x6 + length p128 + (if p_num_bytes > (length p128x6 + length p128) * 16 then 1 else 0) in gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_input_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = pad_to_128_bits auth_input_bytes in let auth_quads = le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = append (append auth_quads c128x6) c128 in let total_bytes = (length auth_quads) * 16 + p_num_bytes in let raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then let raw_quads = append raw_quads c_bytes in let input_bytes = slice (le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = pad_to_128_bits input_bytes in le_bytes_to_seq_quad32 input_padded_bytes else raw_quads in let final_quads = append raw_quads (create 1 length_quad) in enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in let auth_bytes = slice (le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append p128x6 p128) p_bytes else append p128x6 p128 in let plain_bytes = slice (le_seq_quad32_to_bytes plain_raw_quads) 0 p_num_bytes in let cipher:seq quad32 = if p_num_bytes > (length p128x6 + length p128) * 16 then append (append c128x6 c128) c_bytes else append c128x6 c128 in let cipher_bytes = slice (le_seq_quad32_to_bytes cipher) 0 p_num_bytes in length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\ cipher_bytes == fst (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ le_quad32_to_bytes enc_hash == snd (gcm_encrypt_LE alg (seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
[]
Vale.AES.GCM.gcm_blocks_helper
{ "file_name": "vale/code/crypto/aes/Vale.AES.GCM.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128x6: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> c128x6: 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 -> a_num_bytes: Prims.nat -> iv: Vale.AES.GCM_s.supported_iv_LE -> j0_BE: Vale.Def.Types_s.quad32 -> h: Vale.Def.Types_s.quad32 -> enc_hash: Vale.Def.Types_s.quad32 -> length_quad: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\ p_num_bytes < FStar.Seq.Base.length p128x6 * 16 + FStar.Seq.Base.length p128 * 16 + 16 /\ FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\ a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length p128x6 == FStar.Seq.Base.length c128x6 /\ FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\ FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\ FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_s.is_aes_key_LE alg key /\ j0_BE = Vale.AES.GCM_s.compute_iv_BE h iv /\ h = Vale.AES.AES_s.aes_encrypt_LE alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\ length_quad == Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 (Vale.Def.Words_s.Mkfour 0 0 0 0) (8 * a_num_bytes) 1) (8 * p_num_bytes) 0) /\ (let ctr_BE_1 = j0_BE in let ctr_BE_2 = Vale.AES.GCTR_s.inc32 j0_BE 1 in let plain = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bound = FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128 + (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> 1 | _ -> 0) in Vale.AES.GCTR.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\ (let auth_raw_quads = (match a_num_bytes > FStar.Seq.Base.length a128 * 16 with | true -> FStar.Seq.Base.append a128 a_bytes | _ -> a128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let auth_input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let auth_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits auth_input_bytes in let auth_quads = Vale.Def.Types_s.le_bytes_to_seq_quad32 auth_padded_bytes in let raw_quads = FStar.Seq.Base.append (FStar.Seq.Base.append auth_quads c128x6) c128 in let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in let raw_quads = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> let raw_quads = FStar.Seq.Base.append raw_quads c_bytes in let input_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes raw_quads) 0 total_bytes in let input_padded_bytes = Vale.AES.GCTR_s.pad_to_128_bits input_bytes in Vale.Def.Types_s.le_bytes_to_seq_quad32 input_padded_bytes | _ -> raw_quads) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let final_quads = FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad) in enc_hash == Vale.AES.GCTR_s.gctr_encrypt_block ctr_BE_1 (Vale.AES.GHash_s.ghash_LE h final_quads) alg key 0))) (ensures (let auth_raw_quads = (match a_num_bytes > FStar.Seq.Base.length a128 * 16 with | true -> FStar.Seq.Base.append a128 a_bytes | _ -> a128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let auth_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes auth_raw_quads) 0 a_num_bytes in let plain_raw_quads = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append p128x6 p128) p_bytes | _ -> FStar.Seq.Base.append p128x6 p128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 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 = (match p_num_bytes > (FStar.Seq.Base.length p128x6 + FStar.Seq.Base.length p128) * 16 with | true -> FStar.Seq.Base.append (FStar.Seq.Base.append c128x6 c128) c_bytes | _ -> FStar.Seq.Base.append c128x6 c128) <: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 in let cipher_bytes = FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes cipher) 0 p_num_bytes in FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\ FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\ cipher_bytes == FStar.Pervasives.Native.fst (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes) /\ Vale.Def.Types_s.le_quad32_to_bytes enc_hash == FStar.Pervasives.Native.snd (Vale.AES.GCM_s.gcm_encrypt_LE alg (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE key) iv plain_bytes auth_bytes)))
{ "end_col": 4, "end_line": 585, "start_col": 3, "start_line": 424 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let reseed_interval = pow2 10
let reseed_interval =
false
null
false
pow2 10
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Prims.pow2" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0" let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false let supported_alg = a:hash_alg{ is_supported_alg a }
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val reseed_interval : Prims.pos
[]
Spec.HMAC_DRBG.reseed_interval
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.pos
{ "end_col": 47, "end_line": 24, "start_col": 40, "start_line": 24 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let max_output_length = pow2 16
let max_output_length =
false
null
false
pow2 16
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Prims.pow2" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0" let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false let supported_alg = a:hash_alg{ is_supported_alg a }
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_output_length : Prims.pos
[]
Spec.HMAC_DRBG.max_output_length
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.pos
{ "end_col": 47, "end_line": 25, "start_col": 40, "start_line": 25 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false
let is_supported_alg =
false
null
false
function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Spec.Hash.Definitions.hash_alg", "Prims.bool" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0"
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val is_supported_alg : _: Spec.Hash.Definitions.hash_alg -> Prims.bool
[]
Spec.HMAC_DRBG.is_supported_alg
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Spec.Hash.Definitions.hash_alg -> Prims.bool
{ "end_col": 14, "end_line": 20, "start_col": 23, "start_line": 18 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let supported_alg = a:hash_alg{ is_supported_alg a }
let supported_alg =
false
null
false
a: hash_alg{is_supported_alg a}
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.HMAC_DRBG.is_supported_alg" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0" let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val supported_alg : Type0
[]
Spec.HMAC_DRBG.supported_alg
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 52, "end_line": 22, "start_col": 20, "start_line": 22 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let max_length = pow2 16
let max_length =
false
null
false
pow2 16
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Prims.pow2" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0" let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false let supported_alg = a:hash_alg{ is_supported_alg a } let reseed_interval = pow2 10
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_length : Prims.pos
[]
Spec.HMAC_DRBG.max_length
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.pos
{ "end_col": 47, "end_line": 26, "start_col": 40, "start_line": 26 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let max_personalization_string_length = pow2 16
let max_personalization_string_length =
false
null
false
pow2 16
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Prims.pow2" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0" let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false let supported_alg = a:hash_alg{ is_supported_alg a } let reseed_interval = pow2 10 let max_output_length = pow2 16
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_personalization_string_length : Prims.pos
[]
Spec.HMAC_DRBG.max_personalization_string_length
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.pos
{ "end_col": 47, "end_line": 27, "start_col": 40, "start_line": 27 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let max_additional_input_length = pow2 16
let max_additional_input_length =
false
null
false
pow2 16
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Prims.pow2" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0" let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false let supported_alg = a:hash_alg{ is_supported_alg a } let reseed_interval = pow2 10 let max_output_length = pow2 16 let max_length = pow2 16
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val max_additional_input_length : Prims.pos
[]
Spec.HMAC_DRBG.max_additional_input_length
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Prims.pos
{ "end_col": 47, "end_line": 28, "start_col": 40, "start_line": 28 }
Prims.Tot
[ { "abbrev": false, "full_module": "Spec.Agile.HMAC", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let min_length (a:supported_alg) = match a with | SHA1 -> 16 | SHA2_256 | SHA2_384 | SHA2_512 -> 32
let min_length (a: supported_alg) =
false
null
false
match a with | SHA1 -> 16 | SHA2_256 | SHA2_384 | SHA2_512 -> 32
{ "checked_file": "Spec.HMAC_DRBG.fsti.checked", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.HMAC.fsti.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.HMAC_DRBG.fsti" }
[ "total" ]
[ "Spec.HMAC_DRBG.supported_alg", "Prims.int" ]
[]
module Spec.HMAC_DRBG open Lib.IntTypes open FStar.Seq open FStar.Mul open Spec.Hash.Definitions open Spec.Agile.HMAC /// HMAC-DRBG /// /// See 10.1.2 in /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf /// #set-options "--max_fuel 0 --max_ifuel 0" let is_supported_alg = function | SHA1 | SHA2_256 | SHA2_384 | SHA2_512 -> true | _ -> false let supported_alg = a:hash_alg{ is_supported_alg a } let reseed_interval = pow2 10 let max_output_length = pow2 16 let max_length = pow2 16 let max_personalization_string_length = pow2 16 let max_additional_input_length = pow2 16 /// See p.54 /// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf
false
true
Spec.HMAC_DRBG.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val min_length : a: Spec.HMAC_DRBG.supported_alg -> Prims.int
[]
Spec.HMAC_DRBG.min_length
{ "file_name": "specs/drbg/Spec.HMAC_DRBG.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Spec.HMAC_DRBG.supported_alg -> Prims.int
{ "end_col": 40, "end_line": 35, "start_col": 2, "start_line": 33 }
Prims.Tot
val le_to_n (s:Seq.seq u8) : Tot nat
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let le_to_n s = E.le_to_n s
val le_to_n (s:Seq.seq u8) : Tot nat let le_to_n s =
false
null
false
E.le_to_n s
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[ "total" ]
[ "FStar.Seq.Base.seq", "LowStar.PrefixFreezableBuffer.u8", "FStar.Endianness.le_to_n", "Prims.nat" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0"
false
true
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val le_to_n (s:Seq.seq u8) : Tot nat
[]
LowStar.PrefixFreezableBuffer.le_to_n
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
s: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8 -> Prims.nat
{ "end_col": 27, "end_line": 43, "start_col": 16, "start_line": 43 }
Prims.Tot
val prefix_freezable_preorder : srel u8
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let prefix_freezable_preorder = pre
val prefix_freezable_preorder : srel u8 let prefix_freezable_preorder =
false
null
false
pre
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[ "total" ]
[ "LowStar.PrefixFreezableBuffer.pre" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s
false
true
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val prefix_freezable_preorder : srel u8
[]
LowStar.PrefixFreezableBuffer.prefix_freezable_preorder
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
LowStar.Monotonic.Buffer.srel LowStar.PrefixFreezableBuffer.u8
{ "end_col": 35, "end_line": 45, "start_col": 32, "start_line": 45 }
FStar.HyperStack.ST.Stack
val recall_frozen_until (b:buffer) (n:nat) : Stack unit (requires fun h -> (recallable b \/ live h b) /\ b `witnessed` frozen_until_at_least n) (ensures fun h0 _ h1 -> h0 == h1 /\ frozen_until_at_least n (as_seq h1 b))
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let recall_frozen_until b n = recall_p b (frozen_until_at_least n)
val recall_frozen_until (b:buffer) (n:nat) : Stack unit (requires fun h -> (recallable b \/ live h b) /\ b `witnessed` frozen_until_at_least n) (ensures fun h0 _ h1 -> h0 == h1 /\ frozen_until_at_least n (as_seq h1 b)) let recall_frozen_until b n =
true
null
false
recall_p b (frozen_until_at_least n)
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "Prims.nat", "LowStar.Monotonic.Buffer.recall_p", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.PrefixFreezableBuffer.frozen_until_at_least", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4))) let freeze b i = recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i)) let frozen_until_st b = LE.load32_le_i b 0ul let witness_slice b i j snap = witness_p b (slice_is i j snap) let recall_slice b i j snap = recall_p b (slice_is i j snap) let witness_frozen_until b n = witness_p b (frozen_until_at_least n)
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val recall_frozen_until (b:buffer) (n:nat) : Stack unit (requires fun h -> (recallable b \/ live h b) /\ b `witnessed` frozen_until_at_least n) (ensures fun h0 _ h1 -> h0 == h1 /\ frozen_until_at_least n (as_seq h1 b))
[]
LowStar.PrefixFreezableBuffer.recall_frozen_until
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> n: Prims.nat -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 38, "end_line": 145, "start_col": 2, "start_line": 145 }
FStar.HyperStack.ST.Stack
val recall_frozen_until_default (b:buffer) : Stack unit (requires fun h -> recallable b \/ live h b) (ensures fun h0 _ h1 -> h0 == h1 /\ frozen_until_at_least 4 (as_seq h1 b))
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let recall_frozen_until_default b = recall_p b (frozen_until_at_least 4)
val recall_frozen_until_default (b:buffer) : Stack unit (requires fun h -> recallable b \/ live h b) (ensures fun h0 _ h1 -> h0 == h1 /\ frozen_until_at_least 4 (as_seq h1 b)) let recall_frozen_until_default b =
true
null
false
recall_p b (frozen_until_at_least 4)
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "LowStar.Monotonic.Buffer.recall_p", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.PrefixFreezableBuffer.frozen_until_at_least", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4))) let freeze b i = recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i)) let frozen_until_st b = LE.load32_le_i b 0ul let witness_slice b i j snap = witness_p b (slice_is i j snap) let recall_slice b i j snap = recall_p b (slice_is i j snap) let witness_frozen_until b n = witness_p b (frozen_until_at_least n) let recall_frozen_until b n = recall_p b (frozen_until_at_least n)
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val recall_frozen_until_default (b:buffer) : Stack unit (requires fun h -> recallable b \/ live h b) (ensures fun h0 _ h1 -> h0 == h1 /\ frozen_until_at_least 4 (as_seq h1 b))
[]
LowStar.PrefixFreezableBuffer.recall_frozen_until_default
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 38, "end_line": 148, "start_col": 2, "start_line": 148 }
FStar.HyperStack.ST.Stack
val recall_slice (b:buffer) (i j:u32) (snap:G.erased (Seq.seq u8)) : Stack unit (requires fun h -> (recallable b \/ live h b) /\ b `witnessed` slice_is i j snap) (ensures fun h0 _ h1 -> h0 == h1 /\ slice_is i j snap (as_seq h1 b))
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let recall_slice b i j snap = recall_p b (slice_is i j snap)
val recall_slice (b:buffer) (i j:u32) (snap:G.erased (Seq.seq u8)) : Stack unit (requires fun h -> (recallable b \/ live h b) /\ b `witnessed` slice_is i j snap) (ensures fun h0 _ h1 -> h0 == h1 /\ slice_is i j snap (as_seq h1 b)) let recall_slice b i j snap =
true
null
false
recall_p b (slice_is i j snap)
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "LowStar.PrefixFreezableBuffer.u32", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "LowStar.PrefixFreezableBuffer.u8", "LowStar.Monotonic.Buffer.recall_p", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.PrefixFreezableBuffer.slice_is", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4))) let freeze b i = recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i)) let frozen_until_st b = LE.load32_le_i b 0ul let witness_slice b i j snap = witness_p b (slice_is i j snap)
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val recall_slice (b:buffer) (i j:u32) (snap:G.erased (Seq.seq u8)) : Stack unit (requires fun h -> (recallable b \/ live h b) /\ b `witnessed` slice_is i j snap) (ensures fun h0 _ h1 -> h0 == h1 /\ slice_is i j snap (as_seq h1 b))
[]
LowStar.PrefixFreezableBuffer.recall_slice
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> i: LowStar.PrefixFreezableBuffer.u32 -> j: LowStar.PrefixFreezableBuffer.u32 -> snap: FStar.Ghost.erased (FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 32, "end_line": 139, "start_col": 2, "start_line": 139 }
FStar.HyperStack.ST.Stack
val witness_frozen_until (b:buffer) (n:nat) : Stack unit (requires fun h -> frozen_until_at_least n (as_seq h b)) (ensures fun h0 _ h1 -> h0 == h1 /\ b `witnessed` frozen_until_at_least n)
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let witness_frozen_until b n = witness_p b (frozen_until_at_least n)
val witness_frozen_until (b:buffer) (n:nat) : Stack unit (requires fun h -> frozen_until_at_least n (as_seq h b)) (ensures fun h0 _ h1 -> h0 == h1 /\ b `witnessed` frozen_until_at_least n) let witness_frozen_until b n =
true
null
false
witness_p b (frozen_until_at_least n)
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "Prims.nat", "LowStar.Monotonic.Buffer.witness_p", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.PrefixFreezableBuffer.frozen_until_at_least", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4))) let freeze b i = recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i)) let frozen_until_st b = LE.load32_le_i b 0ul let witness_slice b i j snap = witness_p b (slice_is i j snap) let recall_slice b i j snap = recall_p b (slice_is i j snap)
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val witness_frozen_until (b:buffer) (n:nat) : Stack unit (requires fun h -> frozen_until_at_least n (as_seq h b)) (ensures fun h0 _ h1 -> h0 == h1 /\ b `witnessed` frozen_until_at_least n)
[]
LowStar.PrefixFreezableBuffer.witness_frozen_until
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> n: Prims.nat -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 39, "end_line": 142, "start_col": 2, "start_line": 142 }
FStar.HyperStack.ST.Stack
val witness_slice (b:buffer) (i j:u32) (snap:G.erased (Seq.seq u8)) : Stack unit (requires fun h -> slice_is i j snap (as_seq h b)) (ensures fun h0 _ h1 -> h0 == h1 /\ b `witnessed` slice_is i j snap)
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let witness_slice b i j snap = witness_p b (slice_is i j snap)
val witness_slice (b:buffer) (i j:u32) (snap:G.erased (Seq.seq u8)) : Stack unit (requires fun h -> slice_is i j snap (as_seq h b)) (ensures fun h0 _ h1 -> h0 == h1 /\ b `witnessed` slice_is i j snap) let witness_slice b i j snap =
true
null
false
witness_p b (slice_is i j snap)
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "LowStar.PrefixFreezableBuffer.u32", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "LowStar.PrefixFreezableBuffer.u8", "LowStar.Monotonic.Buffer.witness_p", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.PrefixFreezableBuffer.slice_is", "Prims.unit" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4))) let freeze b i = recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i)) let frozen_until_st b = LE.load32_le_i b 0ul
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val witness_slice (b:buffer) (i j:u32) (snap:G.erased (Seq.seq u8)) : Stack unit (requires fun h -> slice_is i j snap (as_seq h b)) (ensures fun h0 _ h1 -> h0 == h1 /\ b `witnessed` slice_is i j snap)
[]
LowStar.PrefixFreezableBuffer.witness_slice
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> i: LowStar.PrefixFreezableBuffer.u32 -> j: LowStar.PrefixFreezableBuffer.u32 -> snap: FStar.Ghost.erased (FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8) -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 33, "end_line": 136, "start_col": 2, "start_line": 136 }
FStar.HyperStack.ST.ST
val gcmalloc (r:HS.rid) (len:u32) : ST (b:lbuffer len{frameOf b == r /\ recallable b}) (requires fun _ -> malloc_pre r len) (ensures alloc_post_mem_common)
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b
val gcmalloc (r:HS.rid) (len:u32) : ST (b:lbuffer len{frameOf b == r /\ recallable b}) (requires fun _ -> malloc_pre r len) (ensures alloc_post_mem_common) let gcmalloc r len =
true
null
false
let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); update_frozen_until_alloc b; b
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "FStar.Monotonic.HyperHeap.rid", "LowStar.PrefixFreezableBuffer.u32", "LowStar.PrefixFreezableBuffer.lbuffer", "Prims.l_and", "Prims.eq2", "LowStar.Monotonic.Buffer.frameOf", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.Monotonic.Buffer.recallable", "Prims.unit", "LowStar.PrefixFreezableBuffer.update_frozen_until_alloc", "Prims._assert", "LowStar.Monotonic.Buffer.fresh_loc", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Endianness.le_to_n_zeros", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Monotonic.Buffer.mgcmalloc", "FStar.UInt8.__uint_to_t", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.lmbuffer" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4)
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gcmalloc (r:HS.rid) (len:u32) : ST (b:lbuffer len{frameOf b == r /\ recallable b}) (requires fun _ -> malloc_pre r len) (ensures alloc_post_mem_common)
[]
LowStar.PrefixFreezableBuffer.gcmalloc
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r: FStar.Monotonic.HyperHeap.rid -> len: LowStar.PrefixFreezableBuffer.u32 -> FStar.HyperStack.ST.ST (b: LowStar.PrefixFreezableBuffer.lbuffer len {LowStar.Monotonic.Buffer.frameOf b == r /\ LowStar.Monotonic.Buffer.recallable b})
{ "end_col": 3, "end_line": 74, "start_col": 20, "start_line": 65 }
FStar.HyperStack.ST.StackInline
val alloca (len:u32) : StackInline (lbuffer len) (requires fun _ -> alloca_pre len) (ensures fun h0 b h1 -> alloc_post_mem_common h0 b h1 /\ frameOf b == HS.get_tip h0)
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b
val alloca (len:u32) : StackInline (lbuffer len) (requires fun _ -> alloca_pre len) (ensures fun h0 b h1 -> alloc_post_mem_common h0 b h1 /\ frameOf b == HS.get_tip h0) let alloca len =
true
null
false
let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); update_frozen_until_alloc b; b
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.u32", "LowStar.PrefixFreezableBuffer.lbuffer", "Prims.unit", "LowStar.PrefixFreezableBuffer.update_frozen_until_alloc", "Prims._assert", "LowStar.Monotonic.Buffer.fresh_loc", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "FStar.Endianness.le_to_n_zeros", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.mbuffer", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Monotonic.Buffer.malloca", "FStar.UInt8.__uint_to_t", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.lmbuffer" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val alloca (len:u32) : StackInline (lbuffer len) (requires fun _ -> alloca_pre len) (ensures fun h0 b h1 -> alloc_post_mem_common h0 b h1 /\ frameOf b == HS.get_tip h0)
[]
LowStar.PrefixFreezableBuffer.alloca
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
len: LowStar.PrefixFreezableBuffer.u32 -> FStar.HyperStack.ST.StackInline (LowStar.PrefixFreezableBuffer.lbuffer len)
{ "end_col": 3, "end_line": 96, "start_col": 16, "start_line": 87 }
FStar.HyperStack.ST.Stack
val frozen_until_st (b:buffer) : Stack u32 (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ U32.v r == frozen_until (as_seq h1 b))
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let frozen_until_st b = LE.load32_le_i b 0ul
val frozen_until_st (b:buffer) : Stack u32 (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ U32.v r == frozen_until (as_seq h1 b)) let frozen_until_st b =
true
null
false
LE.load32_le_i b 0ul
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "LowStar.Endianness.load32_le_i", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "FStar.UInt32.__uint_to_t", "LowStar.Endianness.u32", "LowStar.PrefixFreezableBuffer.u32" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4))) let freeze b i = recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i))
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val frozen_until_st (b:buffer) : Stack u32 (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ U32.v r == frozen_until (as_seq h1 b))
[]
LowStar.PrefixFreezableBuffer.frozen_until_st
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> FStar.HyperStack.ST.Stack LowStar.PrefixFreezableBuffer.u32
{ "end_col": 44, "end_line": 133, "start_col": 24, "start_line": 133 }
FStar.HyperStack.ST.ST
val malloc (r:HS.rid) (len:u32) : ST (b:lbuffer len{frameOf b == r /\ freeable b}) (requires fun _ -> malloc_pre r len) (ensures alloc_post_mem_common)
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b
val malloc (r:HS.rid) (len:u32) : ST (b:lbuffer len{frameOf b == r /\ freeable b}) (requires fun _ -> malloc_pre r len) (ensures alloc_post_mem_common) let malloc r len =
true
null
false
let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); update_frozen_until_alloc b; b
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "FStar.Monotonic.HyperHeap.rid", "LowStar.PrefixFreezableBuffer.u32", "LowStar.PrefixFreezableBuffer.lbuffer", "Prims.l_and", "Prims.eq2", "LowStar.Monotonic.Buffer.frameOf", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.Monotonic.Buffer.freeable", "Prims.unit", "LowStar.PrefixFreezableBuffer.update_frozen_until_alloc", "Prims._assert", "LowStar.Monotonic.Buffer.fresh_loc", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Endianness.le_to_n_zeros", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.mbuffer", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Monotonic.Buffer.mmalloc", "FStar.UInt8.__uint_to_t", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.lmbuffer" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val malloc (r:HS.rid) (len:u32) : ST (b:lbuffer len{frameOf b == r /\ freeable b}) (requires fun _ -> malloc_pre r len) (ensures alloc_post_mem_common)
[]
LowStar.PrefixFreezableBuffer.malloc
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
r: FStar.Monotonic.HyperHeap.rid -> len: LowStar.PrefixFreezableBuffer.u32 -> FStar.HyperStack.ST.ST (b: LowStar.PrefixFreezableBuffer.lbuffer len {LowStar.Monotonic.Buffer.frameOf b == r /\ LowStar.Monotonic.Buffer.freeable b})
{ "end_col": 3, "end_line": 85, "start_col": 18, "start_line": 76 }
FStar.HyperStack.ST.Stack
val update_frozen_until_alloc (b: mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4))
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4)
val update_frozen_until_alloc (b: mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) let update_frozen_until_alloc (b: mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) =
true
null
false
LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4)
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.Monotonic.Buffer.mbuffer", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.Monotonic.Buffer.witness_p", "LowStar.PrefixFreezableBuffer.frozen_until_at_least", "Prims.unit", "LowStar.Endianness.store32_le_i", "FStar.UInt32.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "LowStar.Monotonic.Buffer.length", "Prims.eq2", "Prims.int", "LowStar.PrefixFreezableBuffer.frozen_until", "LowStar.Monotonic.Buffer.as_seq", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.witnessed" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_frozen_until_alloc (b: mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4))
[]
LowStar.PrefixFreezableBuffer.update_frozen_until_alloc
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.Monotonic.Buffer.mbuffer LowStar.PrefixFreezableBuffer.u8 LowStar.PrefixFreezableBuffer.prefix_freezable_preorder LowStar.PrefixFreezableBuffer.prefix_freezable_preorder -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 41, "end_line": 63, "start_col": 4, "start_line": 62 }
FStar.HyperStack.ST.Stack
val upd (b:buffer) (i:u32) (v:u8) : Stack unit (requires fun h -> live h b /\ U32.v i < length b /\ U32.v i >= frozen_until (as_seq h b)) (ensures fun h0 _ h1 -> (not (g_is_null b)) /\ modifies (loc_buffer b) h0 h1 /\ live h1 b /\ frozen_until (as_seq h0 b) == frozen_until (as_seq h1 b) /\ as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) v)
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v
val upd (b:buffer) (i:u32) (v:u8) : Stack unit (requires fun h -> live h b /\ U32.v i < length b /\ U32.v i >= frozen_until (as_seq h b)) (ensures fun h0 _ h1 -> (not (g_is_null b)) /\ modifies (loc_buffer b) h0 h1 /\ live h1 b /\ frozen_until (as_seq h0 b) == frozen_until (as_seq h1 b) /\ as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) v) let upd b i v =
true
null
false
recall_p b (frozen_until_at_least 4); upd b i v
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "LowStar.PrefixFreezableBuffer.u32", "LowStar.PrefixFreezableBuffer.u8", "LowStar.Monotonic.Buffer.upd", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "Prims.unit", "LowStar.Monotonic.Buffer.recall_p", "LowStar.PrefixFreezableBuffer.frozen_until_at_least" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val upd (b:buffer) (i:u32) (v:u8) : Stack unit (requires fun h -> live h b /\ U32.v i < length b /\ U32.v i >= frozen_until (as_seq h b)) (ensures fun h0 _ h1 -> (not (g_is_null b)) /\ modifies (loc_buffer b) h0 h1 /\ live h1 b /\ frozen_until (as_seq h0 b) == frozen_until (as_seq h1 b) /\ as_seq h1 b == Seq.upd (as_seq h0 b) (U32.v i) v)
[]
LowStar.PrefixFreezableBuffer.upd
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> i: LowStar.PrefixFreezableBuffer.u32 -> v: LowStar.PrefixFreezableBuffer.u8 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 11, "end_line": 100, "start_col": 2, "start_line": 99 }
FStar.Pervasives.Lemma
val le_pre_post_index (s1 s2: Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i: nat). {:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i)))
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4)))
val le_pre_post_index (s1 s2: Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i: nat). {:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) let le_pre_post_index (s1 s2: Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i: nat). {:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) =
false
null
true
assert (forall (s: Seq.seq u8). Seq.length s >= 4 ==> (forall (i: nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4)))
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[ "lemma" ]
[ "FStar.Seq.Base.seq", "LowStar.PrefixFreezableBuffer.u8", "Prims._assert", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Seq.Base.length", "Prims.nat", "Prims.l_and", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.index", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.Seq.Base.equal", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==>
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val le_pre_post_index (s1 s2: Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i: nat). {:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i)))
[]
LowStar.PrefixFreezableBuffer.le_pre_post_index
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
s1: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8 -> s2: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8 -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length s1 == FStar.Seq.Base.length s2 /\ FStar.Seq.Base.length s1 >= 4 /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 0 0) (FStar.Seq.Base.slice s2 0 0) /\ FStar.Seq.Base.equal (FStar.Seq.Base.slice s1 4 (FStar.Seq.Base.length s1)) (FStar.Seq.Base.slice s2 4 (FStar.Seq.Base.length s2)) ==> (forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s1 i; FStar.Seq.Base.index s2 i} i >= 4 /\ i < FStar.Seq.Base.length s1 ==> FStar.Seq.Base.index s1 i == FStar.Seq.Base.index s2 i))
{ "end_col": 77, "end_line": 125, "start_col": 4, "start_line": 121 }
FStar.HyperStack.ST.Stack
val freeze (b:buffer) (i:u32) : Stack unit (requires fun h -> live h b /\ U32.v i <= length b /\ U32.v i >= frozen_until (as_seq h b)) (ensures fun h0 _ h1 -> (not (g_is_null b)) /\ modifies (loc_buffer b) h0 h1 /\ live h1 b /\ frozen_until (as_seq h1 b) == U32.v i /\ b `witnessed` frozen_until_at_least (U32.v i) /\ (forall (k:nat).{:pattern (Seq.index (as_seq h1 b) k)} //contents from [4, len) remain same (4 <= k /\ k < length b) ==> (Seq.index (as_seq h1 b) k == Seq.index (as_seq h0 b) k)))
[ { "abbrev": true, "full_module": "LowStar.Endianness", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Preorder", "short_module": "P" }, { "abbrev": false, "full_module": "LowStar.Monotonic.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "LowStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let freeze b i = recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i))
val freeze (b:buffer) (i:u32) : Stack unit (requires fun h -> live h b /\ U32.v i <= length b /\ U32.v i >= frozen_until (as_seq h b)) (ensures fun h0 _ h1 -> (not (g_is_null b)) /\ modifies (loc_buffer b) h0 h1 /\ live h1 b /\ frozen_until (as_seq h1 b) == U32.v i /\ b `witnessed` frozen_until_at_least (U32.v i) /\ (forall (k:nat).{:pattern (Seq.index (as_seq h1 b) k)} //contents from [4, len) remain same (4 <= k /\ k < length b) ==> (Seq.index (as_seq h1 b) k == Seq.index (as_seq h0 b) k))) let freeze b i =
true
null
false
recall_p b (frozen_until_at_least 4); FStar.Classical.forall_intro_2 le_pre_post_index; LE.store32_le_i b 0ul i; witness_p b (frozen_until_at_least (U32.v i))
{ "checked_file": "LowStar.PrefixFreezableBuffer.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Endianness.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowStar.PrefixFreezableBuffer.fst" }
[]
[ "LowStar.PrefixFreezableBuffer.buffer", "LowStar.PrefixFreezableBuffer.u32", "LowStar.Monotonic.Buffer.witness_p", "LowStar.PrefixFreezableBuffer.u8", "LowStar.PrefixFreezableBuffer.prefix_freezable_preorder", "LowStar.PrefixFreezableBuffer.frozen_until_at_least", "FStar.UInt32.v", "Prims.unit", "LowStar.Endianness.store32_le_i", "FStar.UInt32.__uint_to_t", "FStar.Classical.forall_intro_2", "FStar.Seq.Base.seq", "Prims.l_imp", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.l_Forall", "Prims.op_LessThan", "FStar.Seq.Base.index", "LowStar.PrefixFreezableBuffer.le_pre_post_index", "LowStar.Monotonic.Buffer.recall_p" ]
[]
(* 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 LowStar.PrefixFreezableBuffer open FStar.HyperStack.ST include LowStar.Monotonic.Buffer module P = FStar.Preorder module G = FStar.Ghost module U8 = FStar.UInt8 module U32 = FStar.UInt32 module Seq = FStar.Seq module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module E = FStar.Endianness module LE = LowStar.Endianness (* * Implementation for LowStar.PrefixfreezableBuffer *) #set-options "--max_fuel 0 --max_ifuel 0" let le_to_n s = E.le_to_n s let prefix_freezable_preorder = pre let prefix_freezable_preorder_elim _ _ = () private let update_frozen_until_alloc (b:mbuffer u8 prefix_freezable_preorder prefix_freezable_preorder) : Stack unit (requires fun h -> live h b /\ length b >= 4 /\ frozen_until (as_seq h b) == 0) (ensures fun h0 _ h1 -> live h1 b /\ modifies (loc_buffer b) h0 h1 /\ frozen_until (as_seq h1 b) == 4 /\ witnessed b (frozen_until_at_least 4)) = LE.store32_le_i b 0ul 4ul; witness_p b (frozen_until_at_least 4) let gcmalloc r len = let h0 = ST.get () in let b = mgcmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let malloc r len = let h0 = ST.get () in let b = mmalloc #_ #prefix_freezable_preorder r 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let alloca len = let h0 = ST.get () in let b = malloca #_ #prefix_freezable_preorder 0uy (U32.add len 4ul) in let h = ST.get () in E.le_to_n_zeros (Seq.slice (as_seq h b) 0 4); assert (fresh_loc (loc_buffer b) h0 h); //TODO: necessary for firing modifies_remove_new_locs lemma? update_frozen_until_alloc b; b let upd b i v = recall_p b (frozen_until_at_least 4); upd b i v (* * This lemma handles the mismatch between the style of the spec * in LE.store_pre and LE.store_post, and the preorder of PrefixFreezableBuffers * Basically the sequence library is missing a lemma that eliminates * equality on two slices to some equality on the base sequences *) let le_pre_post_index (s1 s2:Seq.seq u8) : Lemma (ensures (Seq.length s1 == Seq.length s2 /\ Seq.length s1 >= 4 /\ Seq.equal (Seq.slice s1 0 0) (Seq.slice s2 0 0) /\ Seq.equal (Seq.slice s1 4 (Seq.length s1)) (Seq.slice s2 4 (Seq.length s2))) ==> (forall (i:nat).{:pattern (Seq.index s1 i); (Seq.index s2 i)} (i >= 4 /\ i < Seq.length s1) ==> (Seq.index s1 i == Seq.index s2 i))) = assert (forall (s:Seq.seq u8). Seq.length s >= 4 ==> (forall (i:nat). (i >= 4 /\ i < Seq.length s) ==> Seq.index s i == Seq.index (Seq.slice s 4 (Seq.length s)) (i - 4)))
false
false
LowStar.PrefixFreezableBuffer.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val freeze (b:buffer) (i:u32) : Stack unit (requires fun h -> live h b /\ U32.v i <= length b /\ U32.v i >= frozen_until (as_seq h b)) (ensures fun h0 _ h1 -> (not (g_is_null b)) /\ modifies (loc_buffer b) h0 h1 /\ live h1 b /\ frozen_until (as_seq h1 b) == U32.v i /\ b `witnessed` frozen_until_at_least (U32.v i) /\ (forall (k:nat).{:pattern (Seq.index (as_seq h1 b) k)} //contents from [4, len) remain same (4 <= k /\ k < length b) ==> (Seq.index (as_seq h1 b) k == Seq.index (as_seq h0 b) k)))
[]
LowStar.PrefixFreezableBuffer.freeze
{ "file_name": "ulib/LowStar.PrefixFreezableBuffer.fst", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
b: LowStar.PrefixFreezableBuffer.buffer -> i: LowStar.PrefixFreezableBuffer.u32 -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 47, "end_line": 131, "start_col": 2, "start_line": 128 }
FStar.Pervasives.Lemma
val repeati_extensionality: #a:Type0 -> n:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{i < n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g i acc)) (ensures Loops.repeati n f acc0 == Loops.repeati n g acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end
val repeati_extensionality: #a:Type0 -> n:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{i < n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g i acc)) (ensures Loops.repeati n f acc0 == Loops.repeati n g acc0) let rec repeati_extensionality #a n f g acc0 =
false
null
true
if n = 0 then (Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0) else (Loops.unfold_repeati n f acc0 (n - 1); Loops.unfold_repeati n g acc0 (n - 1); repeati_extensionality #a (n - 1) f g acc0)
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Equality", "Prims.int", "Lib.LoopCombinators.eq_repeati0", "Prims.unit", "Prims.bool", "Lib.Sequence.Lemmas.repeati_extensionality", "Prims.op_Subtraction", "Lib.LoopCombinators.unfold_repeati" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'"
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeati_extensionality: #a:Type0 -> n:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{i < n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g i acc)) (ensures Loops.repeati n f acc0 == Loops.repeati n g acc0)
[ "recursion" ]
Lib.Sequence.Lemmas.repeati_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Prims.nat -> f: (i: Prims.nat{i < n} -> _: a -> a) -> g: (i: Prims.nat{i < n} -> _: a -> a) -> acc0: a -> FStar.Pervasives.Lemma (requires forall (i: Prims.nat{i < n}) (acc: a). f i acc == g i acc) (ensures Lib.LoopCombinators.repeati n f acc0 == Lib.LoopCombinators.repeati n g acc0)
{ "end_col": 48, "end_line": 19, "start_col": 2, "start_line": 13 }
FStar.Pervasives.Lemma
val repeati_right_shift: #a:Type -> n:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{i < 1 + n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g (i + 1) acc)) (ensures Loops.repeati n f (g 0 acc0) == Loops.repeati (n + 1) g acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0
val repeati_right_shift: #a:Type -> n:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{i < 1 + n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g (i + 1) acc)) (ensures Loops.repeati n f (g 0 acc0) == Loops.repeati (n + 1) g acc0) let repeati_right_shift #a n f g acc0 =
false
null
true
let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; Loops.repeati_def n f acc1; Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Addition", "Lib.LoopCombinators.repeati_def", "Prims.unit", "Lib.LoopCombinators.eq_repeat_right", "Lib.LoopCombinators.fixed_a", "Lib.LoopCombinators.unfold_repeat_right", "Lib.LoopCombinators.repeat_right_plus", "Lib.Sequence.Lemmas.repeati_right_extensionality" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeati_right_shift: #a:Type -> n:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{i < 1 + n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g (i + 1) acc)) (ensures Loops.repeati n f (g 0 acc0) == Loops.repeati (n + 1) g acc0)
[]
Lib.Sequence.Lemmas.repeati_right_shift
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Prims.nat -> f: (i: Prims.nat{i < n} -> _: a -> a) -> g: (i: Prims.nat{i < 1 + n} -> _: a -> a) -> acc0: a -> FStar.Pervasives.Lemma (requires forall (i: Prims.nat{i < n}) (acc: a). f i acc == g (i + 1) acc) (ensures Lib.LoopCombinators.repeati n f (g 0 acc0) == Lib.LoopCombinators.repeati (n + 1) g acc0)
{ "end_col": 34, "end_line": 60, "start_col": 39, "start_line": 46 }
FStar.Pervasives.Lemma
val split_len_lemma: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures (let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in len % blocksize = len1 % blocksize /\ n0 * blocksize = len0 /\ n0 + n1 = n))
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0
val split_len_lemma: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures (let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in len % blocksize = len1 % blocksize /\ n0 * blocksize = len0 /\ n0 + n1 = n)) let split_len_lemma blocksize len len0 =
false
null
true
let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; Math.Lemmas.lemma_div_exact len0 blocksize; len0_div_bs blocksize len len0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.nat", "Lib.Sequence.Lemmas.len0_div_bs", "Prims.unit", "FStar.Math.Lemmas.lemma_div_exact", "FStar.Math.Lemmas.lemma_mod_sub_distr", "Prims.int", "Prims.op_Division", "Prims.op_Subtraction" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val split_len_lemma: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures (let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in len % blocksize = len1 % blocksize /\ n0 * blocksize = len0 /\ n0 + n1 = n))
[]
Lib.Sequence.Lemmas.split_len_lemma
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Prims.pos -> len: Prims.nat -> len0: Prims.nat -> FStar.Pervasives.Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures (let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in len % blocksize = len1 % blocksize /\ n0 * blocksize = len0 /\ n0 + n1 = n))
{ "end_col": 32, "end_line": 159, "start_col": 40, "start_line": 147 }
FStar.Pervasives.Lemma
val repeati_right_extensionality: #a:Type -> n:nat -> lo_g:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{lo_g <= i /\ i < lo_g + n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g (lo_g + i) acc)) (ensures Loops.repeat_right 0 n (Loops.fixed_a a) f acc0 == Loops.repeat_right lo_g (lo_g + n) (Loops.fixed_a a) g acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0
val repeati_right_extensionality: #a:Type -> n:nat -> lo_g:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{lo_g <= i /\ i < lo_g + n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g (lo_g + i) acc)) (ensures Loops.repeat_right 0 n (Loops.fixed_a a) f acc0 == Loops.repeat_right lo_g (lo_g + n) (Loops.fixed_a a) g acc0) let repeati_right_extensionality #a n lo_g f g acc0 =
false
null
true
repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.Lemmas.repeat_gen_right_extensionality", "Lib.LoopCombinators.fixed_a", "Prims.unit" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeati_right_extensionality: #a:Type -> n:nat -> lo_g:nat -> f:(i:nat{i < n} -> a -> a) -> g:(i:nat{lo_g <= i /\ i < lo_g + n} -> a -> a) -> acc0:a -> Lemma (requires (forall (i:nat{i < n}) (acc:a). f i acc == g (lo_g + i) acc)) (ensures Loops.repeat_right 0 n (Loops.fixed_a a) f acc0 == Loops.repeat_right lo_g (lo_g + n) (Loops.fixed_a a) g acc0)
[]
Lib.Sequence.Lemmas.repeati_right_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Prims.nat -> lo_g: Prims.nat -> f: (i: Prims.nat{i < n} -> _: a -> a) -> g: (i: Prims.nat{lo_g <= i /\ i < lo_g + n} -> _: a -> a) -> acc0: a -> FStar.Pervasives.Lemma (requires forall (i: Prims.nat{i < n}) (acc: a). f i acc == g (lo_g + i) acc) (ensures Lib.LoopCombinators.repeat_right 0 n (Lib.LoopCombinators.fixed_a a) f acc0 == Lib.LoopCombinators.repeat_right lo_g (lo_g + n) (Lib.LoopCombinators.fixed_a a) g acc0)
{ "end_col": 85, "end_line": 43, "start_col": 2, "start_line": 43 }
FStar.Pervasives.Lemma
val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize)
[ { "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": 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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize)
val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 =
false
null
true
Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize)
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.nat", "FStar.Math.Lemmas.lemma_mult_le_right", "Prims.op_Division", "Prims.unit", "FStar.Math.Lemmas.lemma_div_le" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize)
[]
Lib.Sequence.Lemmas.len0_le_len_fraction
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Prims.pos -> len: Prims.nat -> len0: Prims.nat -> FStar.Pervasives.Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= (len / blocksize) * blocksize)
{ "end_col": 80, "end_line": 392, "start_col": 2, "start_line": 391 }
FStar.Pervasives.Lemma
val split_len_lemma0: blocksize:pos -> n:nat -> len0:nat -> Lemma (requires len0 <= n * blocksize /\ len0 % blocksize = 0) (ensures (let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len % blocksize = 0 /\ len1 % blocksize = 0 /\ n0 + n1 = n /\ n0 * blocksize = len0 /\ n1 * blocksize = len1))
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0
val split_len_lemma0: blocksize:pos -> n:nat -> len0:nat -> Lemma (requires len0 <= n * blocksize /\ len0 % blocksize = 0) (ensures (let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len % blocksize = 0 /\ len1 % blocksize = 0 /\ n0 + n1 = n /\ n0 * blocksize = len0 /\ n1 * blocksize = len1)) let split_len_lemma0 blocksize n len0 =
false
null
true
let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; Math.Lemmas.lemma_div_exact len0 blocksize; Math.Lemmas.lemma_div_exact len1 blocksize; len0_div_bs blocksize len len0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.nat", "Lib.Sequence.Lemmas.len0_div_bs", "Prims.unit", "FStar.Math.Lemmas.lemma_div_exact", "FStar.Math.Lemmas.lemma_mod_sub_distr", "FStar.Math.Lemmas.cancel_mul_mod", "Prims.int", "Prims.op_Division", "Prims.op_Subtraction", "FStar.Mul.op_Star" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val split_len_lemma0: blocksize:pos -> n:nat -> len0:nat -> Lemma (requires len0 <= n * blocksize /\ len0 % blocksize = 0) (ensures (let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len % blocksize = 0 /\ len1 % blocksize = 0 /\ n0 + n1 = n /\ n0 * blocksize = len0 /\ n1 * blocksize = len1))
[]
Lib.Sequence.Lemmas.split_len_lemma0
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Prims.pos -> n: Prims.nat -> len0: Prims.nat -> FStar.Pervasives.Lemma (requires len0 <= n * blocksize /\ len0 % blocksize = 0) (ensures (let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len % blocksize = 0 /\ len1 % blocksize = 0 /\ n0 + n1 = n /\ n0 * blocksize = len0 /\ n1 * blocksize = len1))
{ "end_col": 32, "end_line": 143, "start_col": 39, "start_line": 126 }
Prims.Tot
val repeat_gen_blocks_multi: #inp_t:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> a (mi + n)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0
val repeat_gen_blocks_multi: #inp_t:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> a (mi + n) let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 =
false
null
false
Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "total" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.LoopCombinators.repeat_right", "Lib.Sequence.Lemmas.repeat_gen_blocks_f" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_blocks_multi: #inp_t:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> a (mi + n)
[]
Lib.Sequence.Lemmas.repeat_gen_blocks_multi
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi: Prims.nat -> n: Prims.nat{mi + n <= hi} -> inp: Lib.Sequence.seq inp_t {Lib.Sequence.length inp == n * blocksize} -> a: (i: Prims.nat{i <= hi} -> Type) -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) -> acc0: a mi -> a (mi + n)
{ "end_col": 87, "end_line": 64, "start_col": 2, "start_line": 64 }
Prims.Tot
val map_blocks_acc: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq a{mi + length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> acc0:map_blocks_a a blocksize hi mi -> seq a
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_acc #a blocksize mi hi inp f l acc0 = repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0
val map_blocks_acc: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq a{mi + length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> acc0:map_blocks_a a blocksize hi mi -> seq a let map_blocks_acc #a blocksize mi hi inp f l acc0 =
false
null
false
repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "total" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Lib.Sequence.seq", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Prims.op_Division", "Lib.Sequence.length", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.map_blocks_a", "Lib.Sequence.Lemmas.repeat_gen_blocks", "Lib.Sequence.Lemmas.repeat_gen_blocks_map_f", "Lib.Sequence.Lemmas.repeat_gen_blocks_map_l" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = () let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_acc: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq a{mi + length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> acc0:map_blocks_a a blocksize hi mi -> seq a
[]
Lib.Sequence.Lemmas.map_blocks_acc
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi: Prims.nat -> inp: Lib.Sequence.seq a {mi + Lib.Sequence.length inp / blocksize <= hi} -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> l: (i: Prims.nat{i <= hi} -> rem: Prims.nat{rem < blocksize} -> _: Lib.Sequence.lseq a rem -> Lib.Sequence.lseq a rem) -> acc0: Lib.Sequence.map_blocks_a a blocksize hi mi -> Lib.Sequence.seq a
{ "end_col": 49, "end_line": 655, "start_col": 2, "start_line": 652 }
FStar.Pervasives.Lemma
val len0_div_bs: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize == 0) (ensures len0 / blocksize + (len - len0) / blocksize == len / blocksize)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; }
val len0_div_bs: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize == 0) (ensures len0 / blocksize + (len - len0) / blocksize == len / blocksize) let len0_div_bs blocksize len len0 =
false
null
true
let k = len0 / blocksize in calc ( == ) { k + (len - len0) / blocksize; ( == ) { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; ( == ) { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; ( == ) { () } len / blocksize; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.pos", "Prims.nat", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Addition", "Prims.op_Division", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_div_exact", "Prims.squash", "FStar.Math.Lemmas.division_sub_lemma" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val len0_div_bs: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize == 0) (ensures len0 / blocksize + (len - len0) / blocksize == len / blocksize)
[]
Lib.Sequence.Lemmas.len0_div_bs
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Prims.pos -> len: Prims.nat -> len0: Prims.nat -> FStar.Pervasives.Lemma (requires len0 <= len /\ len0 % blocksize == 0) (ensures len0 / blocksize + (len - len0) / blocksize == len / blocksize)
{ "end_col": 3, "end_line": 123, "start_col": 36, "start_line": 113 }
Prims.Tot
val map_blocks_multi_acc: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi mi -> out:seq a {length out == length acc0 + length inp}
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0
val map_blocks_multi_acc: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi mi -> out:seq a {length out == length acc0 + length inp} let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 =
false
null
false
repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "total" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.map_blocks_a", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "Lib.Sequence.Lemmas.repeat_gen_blocks_map_f" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = ()
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_multi_acc: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi mi -> out:seq a {length out == length acc0 + length inp}
[]
Lib.Sequence.Lemmas.map_blocks_multi_acc
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi: Prims.nat -> n: Prims.nat{mi + n <= hi} -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp == n * blocksize} -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> acc0: Lib.Sequence.map_blocks_a a blocksize hi mi -> out: Lib.Sequence.seq a {Lib.Sequence.length out == Lib.Sequence.length acc0 + Lib.Sequence.length inp}
{ "end_col": 49, "end_line": 648, "start_col": 2, "start_line": 646 }
Prims.Tot
val repeat_gen_blocks: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq inp_t{mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> l:(i:nat{i <= hi} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c) -> acci:a mi -> c
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc
val repeat_gen_blocks: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq inp_t{mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> l:(i:nat{i <= hi} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c) -> acci:a mi -> c let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 =
false
null
false
let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "total" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Lib.Sequence.seq", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Prims.op_Division", "Lib.Sequence.length", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "Prims.unit", "FStar.Math.Lemmas.cancel_mul_div", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "Prims.int", "Prims.op_Modulus" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = ()
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_blocks: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq inp_t{mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> l:(i:nat{i <= hi} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c) -> acci:a mi -> c
[]
Lib.Sequence.Lemmas.repeat_gen_blocks
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi: Prims.nat -> inp: Lib.Sequence.seq inp_t {mi + Lib.Sequence.length inp / blocksize <= hi} -> a: (i: Prims.nat{i <= hi} -> Type) -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) -> l: ( i: Prims.nat{i <= hi} -> len: Prims.nat{len < blocksize} -> _: Lib.Sequence.lseq inp_t len -> _: a i -> c) -> acci: a mi -> c
{ "end_col": 26, "end_line": 78, "start_col": 64, "start_line": 70 }
FStar.Pervasives.Lemma
val repeat_blocks_multi_extensionality: #a:Type0 -> #b:Type0 -> blocksize:size_pos -> inp:seq a{length inp % blocksize = 0} -> f:(lseq a blocksize -> b -> b) -> g:(lseq a blocksize -> b -> b) -> init:b -> Lemma (requires (forall (block:lseq a blocksize) (acc:b). f block acc == g block acc)) (ensures repeat_blocks_multi blocksize inp f init == repeat_blocks_multi blocksize inp g init)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init
val repeat_blocks_multi_extensionality: #a:Type0 -> #b:Type0 -> blocksize:size_pos -> inp:seq a{length inp % blocksize = 0} -> f:(lseq a blocksize -> b -> b) -> g:(lseq a blocksize -> b -> b) -> init:b -> Lemma (requires (forall (block:lseq a blocksize) (acc:b). f block acc == g block acc)) (ensures repeat_blocks_multi blocksize inp f init == repeat_blocks_multi blocksize inp g init) let repeat_blocks_multi_extensionality #a #b blocksize inp f g init =
false
null
true
let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i: nat{i < nb}) (acc: b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Lib.Sequence.seq", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Lib.Sequence.length", "Lib.Sequence.lseq", "Lib.Sequence.Lemmas.repeati_extensionality", "Prims.unit", "FStar.Classical.forall_intro_2", "Prims.nat", "Prims.op_LessThan", "Prims.eq2", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Seq.Properties.slice_slice", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Math.Lemmas.lemma_mult_le_right", "Lib.Sequence.lemma_repeat_blocks_multi", "Lib.Sequence.repeat_blocks_f", "Prims.op_Division" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_blocks_multi_extensionality: #a:Type0 -> #b:Type0 -> blocksize:size_pos -> inp:seq a{length inp % blocksize = 0} -> f:(lseq a blocksize -> b -> b) -> g:(lseq a blocksize -> b -> b) -> init:b -> Lemma (requires (forall (block:lseq a blocksize) (acc:b). f block acc == g block acc)) (ensures repeat_blocks_multi blocksize inp f init == repeat_blocks_multi blocksize inp g init)
[]
Lib.Sequence.Lemmas.repeat_blocks_multi_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp % blocksize = 0} -> f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> g: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> init: b -> FStar.Pervasives.Lemma (requires forall (block: Lib.Sequence.lseq a blocksize) (acc: b). f block acc == g block acc) (ensures Lib.Sequence.repeat_blocks_multi blocksize inp f init == Lib.Sequence.repeat_blocks_multi blocksize inp g init)
{ "end_col": 44, "end_line": 605, "start_col": 69, "start_line": 591 }
FStar.Pervasives.Lemma
val repeat_blocks_is_repeat_gen_blocks: #a:Type0 -> #b:Type0 -> #c:Type0 -> hi:nat -> blocksize:size_pos -> inp:seq a{length inp / blocksize <= hi} -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (repeat_blocks #a #b #c blocksize inp f l acc0 == repeat_gen_blocks #a #c blocksize 0 hi inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; }
val repeat_blocks_is_repeat_gen_blocks: #a:Type0 -> #b:Type0 -> #c:Type0 -> hi:nat -> blocksize:size_pos -> inp:seq a{length inp / blocksize <= hi} -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (repeat_blocks #a #b #c blocksize inp f l acc0 == repeat_gen_blocks #a #c blocksize 0 hi inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0) let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 =
false
null
true
let len = length inp in let nb = len / blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc ( == ) { repeat_blocks_multi blocksize blocks f acc0; ( == ) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Lib.IntTypes.size_pos", "Lib.Sequence.seq", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Division", "Lib.Sequence.length", "Lib.Sequence.lseq", "Prims.op_LessThan", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.Sequence.repeat_blocks_multi", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "Lib.LoopCombinators.fixed_a", "Lib.LoopCombinators.fixed_i", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.repeat_blocks_multi_is_repeat_gen_blocks_multi", "Prims.squash", "Lib.Sequence.Lemmas.lemma_repeat_blocks_via_multi", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "FStar.Math.Lemmas.cancel_mul_mod", "FStar.Math.Lemmas.cancel_mul_div", "Prims.int" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_blocks_is_repeat_gen_blocks: #a:Type0 -> #b:Type0 -> #c:Type0 -> hi:nat -> blocksize:size_pos -> inp:seq a{length inp / blocksize <= hi} -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (repeat_blocks #a #b #c blocksize inp f l acc0 == repeat_gen_blocks #a #c blocksize 0 hi inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0)
[]
Lib.Sequence.Lemmas.repeat_blocks_is_repeat_gen_blocks
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hi: Prims.nat -> blocksize: Lib.IntTypes.size_pos -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp / blocksize <= hi} -> f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> l: (len: Prims.nat{len < blocksize} -> s: Lib.Sequence.lseq a len -> _: b -> c) -> acc0: b -> FStar.Pervasives.Lemma (ensures Lib.Sequence.repeat_blocks blocksize inp f l acc0 == Lib.Sequence.Lemmas.repeat_gen_blocks blocksize 0 hi inp (Lib.LoopCombinators.fixed_a b) (Lib.LoopCombinators.fixed_i f) (Lib.LoopCombinators.fixed_i l) acc0)
{ "end_col": 5, "end_line": 515, "start_col": 75, "start_line": 501 }
FStar.Pervasives.Lemma
val repeat_blocks_extensionality: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> inp:seq a -> f1:(lseq a blocksize -> b -> b) -> f2:(lseq a blocksize -> b -> b) -> l1:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> l2:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (requires (forall (block:lseq a blocksize) (acc:b). f1 block acc == f2 block acc) /\ (forall (rem:nat{rem < blocksize}) (last:lseq a rem) (acc:b). l1 rem last acc == l2 rem last acc)) (ensures repeat_blocks blocksize inp f1 l1 acc0 == repeat_blocks blocksize inp f2 l2 acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0
val repeat_blocks_extensionality: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> inp:seq a -> f1:(lseq a blocksize -> b -> b) -> f2:(lseq a blocksize -> b -> b) -> l1:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> l2:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (requires (forall (block:lseq a blocksize) (acc:b). f1 block acc == f2 block acc) /\ (forall (rem:nat{rem < blocksize}) (last:lseq a rem) (acc:b). l1 rem last acc == l2 rem last acc)) (ensures repeat_blocks blocksize inp f1 l1 acc0 == repeat_blocks blocksize inp f2 l2 acc0) let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 =
false
null
true
let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i: nat{i < nb}) (acc: b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Lib.Sequence.seq", "Lib.Sequence.lseq", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.Lemmas.repeati_extensionality", "Prims.unit", "FStar.Classical.forall_intro_2", "Prims.eq2", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Seq.Properties.slice_slice", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Math.Lemmas.lemma_mult_le_right", "Lib.Sequence.lemma_repeat_blocks", "Lib.LoopCombinators.repeati", "Lib.Sequence.repeat_blocks_f", "Prims.int", "Prims.op_Division", "Lib.Sequence.length" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties ////////////////////////
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_blocks_extensionality: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> inp:seq a -> f1:(lseq a blocksize -> b -> b) -> f2:(lseq a blocksize -> b -> b) -> l1:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> l2:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (requires (forall (block:lseq a blocksize) (acc:b). f1 block acc == f2 block acc) /\ (forall (rem:nat{rem < blocksize}) (last:lseq a rem) (acc:b). l1 rem last acc == l2 rem last acc)) (ensures repeat_blocks blocksize inp f1 l1 acc0 == repeat_blocks blocksize inp f2 l2 acc0)
[]
Lib.Sequence.Lemmas.repeat_blocks_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> inp: Lib.Sequence.seq a -> f1: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> f2: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> l1: (len: Prims.nat{len < blocksize} -> s: Lib.Sequence.lseq a len -> _: b -> c) -> l2: (len: Prims.nat{len < blocksize} -> s: Lib.Sequence.lseq a len -> _: b -> c) -> acc0: b -> FStar.Pervasives.Lemma (requires (forall (block: Lib.Sequence.lseq a blocksize) (acc: b). f1 block acc == f2 block acc) /\ (forall (rem: Prims.nat{rem < blocksize}) (last: Lib.Sequence.lseq a rem) (acc: b). l1 rem last acc == l2 rem last acc)) (ensures Lib.Sequence.repeat_blocks blocksize inp f1 l1 acc0 == Lib.Sequence.repeat_blocks blocksize inp f2 l2 acc0)
{ "end_col": 46, "end_line": 451, "start_col": 74, "start_line": 434 }
FStar.Pervasives.Lemma
val map_blocks_extensionality: #a:Type0 -> blocksize:size_pos -> inp:seq a -> f:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize) -> l_f:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) -> g:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize) -> l_g:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) -> Lemma (requires (let n = length inp / blocksize in (forall (i:nat{i < n}) (b_v:lseq a blocksize). f i b_v == g i b_v) /\ (forall (rem:nat{rem < blocksize}) (b_v:lseq a rem). l_f n rem b_v == l_g n rem b_v))) (ensures map_blocks blocksize inp f l_f == map_blocks blocksize inp g l_g)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g
val map_blocks_extensionality: #a:Type0 -> blocksize:size_pos -> inp:seq a -> f:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize) -> l_f:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) -> g:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize) -> l_g:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) -> Lemma (requires (let n = length inp / blocksize in (forall (i:nat{i < n}) (b_v:lseq a blocksize). f i b_v == g i b_v) /\ (forall (rem:nat{rem < blocksize}) (b_v:lseq a rem). l_f n rem b_v == l_g n rem b_v))) (ensures map_blocks blocksize inp f l_f == map_blocks blocksize inp g l_g) let map_blocks_extensionality #a blocksize inp f l_f g l_g =
false
null
true
let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Lib.Sequence.seq", "Lib.Sequence.block", "Lib.Sequence.length", "Lib.Sequence.lseq", "Lib.Sequence.last", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.Lemmas.map_blocks_multi_extensionality", "Prims.unit", "Lib.Sequence.lemma_map_blocks", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "Prims.int", "Prims.op_Division", "Prims.nat" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_extensionality: #a:Type0 -> blocksize:size_pos -> inp:seq a -> f:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize) -> l_f:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) -> g:(block (length inp) blocksize -> lseq a blocksize -> lseq a blocksize) -> l_g:(last (length inp) blocksize -> rem:size_nat{rem < blocksize} -> s:lseq a rem -> lseq a rem) -> Lemma (requires (let n = length inp / blocksize in (forall (i:nat{i < n}) (b_v:lseq a blocksize). f i b_v == g i b_v) /\ (forall (rem:nat{rem < blocksize}) (b_v:lseq a rem). l_f n rem b_v == l_g n rem b_v))) (ensures map_blocks blocksize inp f l_f == map_blocks blocksize inp g l_g)
[]
Lib.Sequence.Lemmas.map_blocks_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> inp: Lib.Sequence.seq a -> f: (_: Lib.Sequence.block (Lib.Sequence.length inp) blocksize -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> l_f: ( _: Lib.Sequence.last (Lib.Sequence.length inp) blocksize -> rem: Lib.IntTypes.size_nat{rem < blocksize} -> s: Lib.Sequence.lseq a rem -> Lib.Sequence.lseq a rem) -> g: (_: Lib.Sequence.block (Lib.Sequence.length inp) blocksize -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> l_g: ( _: Lib.Sequence.last (Lib.Sequence.length inp) blocksize -> rem: Lib.IntTypes.size_nat{rem < blocksize} -> s: Lib.Sequence.lseq a rem -> Lib.Sequence.lseq a rem) -> FStar.Pervasives.Lemma (requires (let n = Lib.Sequence.length inp / blocksize in (forall (i: Prims.nat{i < n}) (b_v: Lib.Sequence.lseq a blocksize). f i b_v == g i b_v) /\ (forall (rem: Prims.nat{rem < blocksize}) (b_v: Lib.Sequence.lseq a rem). l_f n rem b_v == l_g n rem b_v))) (ensures Lib.Sequence.map_blocks blocksize inp f l_f == Lib.Sequence.map_blocks blocksize inp g l_g)
{ "end_col": 61, "end_line": 639, "start_col": 60, "start_line": 632 }
FStar.Pervasives.Lemma
val lemma_repeat_blocks_via_multi: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> inp:seq a -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_mod nb blocksize; let acc = repeat_blocks_multi blocksize blocks f acc0 in repeat_blocks #a #b blocksize inp f l acc0 == l rem last acc)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; }
val lemma_repeat_blocks_via_multi: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> inp:seq a -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_mod nb blocksize; let acc = repeat_blocks_multi blocksize blocks f acc0 in repeat_blocks #a #b blocksize inp f l acc0 == l rem last acc) let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 =
false
null
true
let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i: nat{i < nb}) (acc: b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc ( == ) { Loops.repeati nb f_rep acc0; ( == ) { (Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0) } Loops.repeati nb f_rep_b acc0; ( == ) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Lib.Sequence.seq", "Lib.Sequence.lseq", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.LoopCombinators.repeati", "Lib.Sequence.repeat_blocks_multi", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.repeati_extensionality", "FStar.Classical.forall_intro_2", "Prims.squash", "Lib.Sequence.lemma_repeat_blocks_multi", "Lib.Sequence.lemma_repeat_blocks", "Prims.l_True", "FStar.Pervasives.pattern", "FStar.Seq.Properties.slice_slice", "FStar.Mul.op_Star", "Prims.op_Addition", "FStar.Math.Lemmas.lemma_mult_le_right", "Lib.Sequence.repeat_blocks_f", "FStar.Math.Lemmas.cancel_mul_mod", "FStar.Math.Lemmas.cancel_mul_div", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Prims.int", "Prims.op_Division", "Lib.Sequence.length" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_repeat_blocks_via_multi: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> inp:seq a -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_mod nb blocksize; let acc = repeat_blocks_multi blocksize blocks f acc0 in repeat_blocks #a #b blocksize inp f l acc0 == l rem last acc)
[]
Lib.Sequence.Lemmas.lemma_repeat_blocks_via_multi
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> inp: Lib.Sequence.seq a -> f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> l: (len: Prims.nat{len < blocksize} -> s: Lib.Sequence.lseq a len -> _: b -> c) -> acc0: b -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = FStar.Seq.Base.slice inp 0 (nb * blocksize) in let last = FStar.Seq.Base.slice inp (nb * blocksize) len in [@@ FStar.Pervasives.inline_let ]let _ = FStar.Math.Lemmas.cancel_mul_mod nb blocksize in let acc = Lib.Sequence.repeat_blocks_multi blocksize blocks f acc0 in Lib.Sequence.repeat_blocks blocksize inp f l acc0 == l rem last acc))
{ "end_col": 3, "end_line": 476, "start_col": 67, "start_line": 454 }
FStar.Pervasives.Lemma
val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc)
[ { "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": 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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc)
val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc =
false
null
true
let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc ( <= ) { i_b1 * blocksize + blocksize; ( <= ) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; ( == ) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc ( == ) { len0 + i_b1 * blocksize; ( == ) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; ( == ) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc)
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.l_and", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Prims.op_Division", "Prims._assert", "Prims.unit", "FStar.Seq.Properties.slice_slice", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.div_exact_r", "Prims.squash", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.lemma_mult_le_right", "Prims.op_Subtraction", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.Sequence.Lemmas.repeat_gen_blocks_f", "Lib.Sequence.Lemmas.split_len_lemma0" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc)
[]
Lib.Sequence.Lemmas.aux_repeat_bf_s1
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize == 0} -> mi: Prims.nat -> hi: Prims.nat -> n: Prims.nat{mi + n <= hi} -> inp: Lib.Sequence.seq inp_t {len0 <= Lib.Sequence.length inp /\ Lib.Sequence.length inp == n * blocksize} -> a: (i: Prims.nat{i <= hi} -> Type) -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) -> i: Prims.nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc: a i -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma0 blocksize n len0 in let t1 = FStar.Seq.Base.slice inp len0 len in let repeat_bf_s1 = Lib.Sequence.Lemmas.repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = Lib.Sequence.Lemmas.repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc))
{ "end_col": 46, "end_line": 267, "start_col": 66, "start_line": 233 }
FStar.Pervasives.Lemma
val repeat_blocks_multi_is_repeat_gen_blocks_multi: #a:Type0 -> #b:Type0 -> hi:nat -> blocksize:size_pos -> inp:seq a{length inp % blocksize = 0 /\ length inp / blocksize <= hi} -> f:(lseq a blocksize -> b -> b) -> acc0:b -> Lemma (let n = length inp / blocksize in Math.Lemmas.div_exact_r (length inp) blocksize; repeat_blocks_multi #a #b blocksize inp f acc0 == repeat_gen_blocks_multi #a blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; }
val repeat_blocks_multi_is_repeat_gen_blocks_multi: #a:Type0 -> #b:Type0 -> hi:nat -> blocksize:size_pos -> inp:seq a{length inp % blocksize = 0 /\ length inp / blocksize <= hi} -> f:(lseq a blocksize -> b -> b) -> acc0:b -> Lemma (let n = length inp / blocksize in Math.Lemmas.div_exact_r (length inp) blocksize; repeat_blocks_multi #a #b blocksize inp f acc0 == repeat_gen_blocks_multi #a blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0) let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 =
false
null
true
let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i: nat{i < n}) (acc: b) : Lemma (f_rep i acc == f_gen i acc) = () in calc ( == ) { repeat_blocks_multi #a #b blocksize inp f acc0; ( == ) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; ( == ) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; ( == ) { (Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0) } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Lib.IntTypes.size_pos", "Lib.Sequence.seq", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Lib.Sequence.length", "Prims.op_LessThanOrEqual", "Prims.op_Division", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.Sequence.repeat_blocks_multi", "Lib.LoopCombinators.repeat_right", "Lib.LoopCombinators.fixed_a", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.LoopCombinators.repeati", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.lemma_repeat_blocks_multi", "Prims.squash", "Lib.LoopCombinators.repeati_def", "Lib.Sequence.repeat_blocks_f", "Lib.Sequence.Lemmas.repeat_gen_right_extensionality", "FStar.Classical.forall_intro_2", "Prims.op_LessThan", "Prims.l_True", "FStar.Pervasives.pattern", "Prims.op_Addition", "Lib.Sequence.Lemmas.repeat_gen_blocks_f", "Lib.LoopCombinators.fixed_i", "FStar.Math.Lemmas.div_exact_r" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_blocks_multi_is_repeat_gen_blocks_multi: #a:Type0 -> #b:Type0 -> hi:nat -> blocksize:size_pos -> inp:seq a{length inp % blocksize = 0 /\ length inp / blocksize <= hi} -> f:(lseq a blocksize -> b -> b) -> acc0:b -> Lemma (let n = length inp / blocksize in Math.Lemmas.div_exact_r (length inp) blocksize; repeat_blocks_multi #a #b blocksize inp f acc0 == repeat_gen_blocks_multi #a blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0)
[]
Lib.Sequence.Lemmas.repeat_blocks_multi_is_repeat_gen_blocks_multi
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hi: Prims.nat -> blocksize: Lib.IntTypes.size_pos -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp % blocksize = 0 /\ Lib.Sequence.length inp / blocksize <= hi} -> f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> acc0: b -> FStar.Pervasives.Lemma (ensures (let n = Lib.Sequence.length inp / blocksize in [@@ FStar.Pervasives.inline_let ]let _ = FStar.Math.Lemmas.div_exact_r (Lib.Sequence.length inp) blocksize in Lib.Sequence.repeat_blocks_multi blocksize inp f acc0 == Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize 0 hi n inp (Lib.LoopCombinators.fixed_a b) (Lib.LoopCombinators.fixed_i f) acc0))
{ "end_col": 5, "end_line": 498, "start_col": 82, "start_line": 479 }
FStar.Pervasives.Lemma
val map_blocks_acc_is_map_blocks0: #a:Type0 -> blocksize:size_pos -> hi:nat -> inp:seq a{length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> Lemma (map_blocks_acc #a blocksize 0 hi inp f l Seq.empty `Seq.equal` map_blocks #a blocksize inp f l)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_acc_is_map_blocks0 #a blocksize hi inp f l = let len = length inp in let n = len / blocksize in let f_sh = f_shift blocksize 0 hi n f in let l_sh = l_shift blocksize 0 hi n l in calc (==) { map_blocks_acc #a blocksize 0 hi inp f l Seq.empty; (==) { map_blocks_acc_is_map_blocks blocksize 0 hi inp f l Seq.empty } Seq.append Seq.empty (map_blocks #a blocksize inp f_sh l_sh); (==) { Seq.Base.append_empty_l (map_blocks #a blocksize inp f_sh l_sh) } map_blocks #a blocksize inp f_sh l_sh; (==) { map_blocks_extensionality #a blocksize inp f l f_sh l_sh } map_blocks #a blocksize inp f l; }
val map_blocks_acc_is_map_blocks0: #a:Type0 -> blocksize:size_pos -> hi:nat -> inp:seq a{length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> Lemma (map_blocks_acc #a blocksize 0 hi inp f l Seq.empty `Seq.equal` map_blocks #a blocksize inp f l) let map_blocks_acc_is_map_blocks0 #a blocksize hi inp f l =
false
null
true
let len = length inp in let n = len / blocksize in let f_sh = f_shift blocksize 0 hi n f in let l_sh = l_shift blocksize 0 hi n l in calc ( == ) { map_blocks_acc #a blocksize 0 hi inp f l Seq.empty; ( == ) { map_blocks_acc_is_map_blocks blocksize 0 hi inp f l Seq.empty } Seq.append Seq.empty (map_blocks #a blocksize inp f_sh l_sh); ( == ) { Seq.Base.append_empty_l (map_blocks #a blocksize inp f_sh l_sh) } map_blocks #a blocksize inp f_sh l_sh; ( == ) { map_blocks_extensionality #a blocksize inp f l f_sh l_sh } map_blocks #a blocksize inp f l; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Lib.Sequence.seq", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Division", "Lib.Sequence.length", "Prims.op_LessThan", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.Sequence.Lemmas.map_blocks_acc", "FStar.Seq.Base.empty", "Lib.Sequence.map_blocks", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Seq.Base.append", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.map_blocks_acc_is_map_blocks", "Prims.squash", "FStar.Seq.Base.append_empty_l", "Lib.Sequence.Lemmas.map_blocks_extensionality", "Lib.Sequence.Lemmas.l_shift", "Lib.Sequence.Lemmas.f_shift", "Prims.int" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = () let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0 let map_blocks_acc #a blocksize mi hi inp f l acc0 = repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0 let map_blocks_acc_length #a blocksize mi hi inp f l acc0 = () let map_blocks_multi_acc_is_repeat_gen_blocks_multi #a blocksize mi hi n inp f acc0 = () let map_blocks_acc_is_repeat_gen_blocks #a blocksize mi hi inp f l acc0 = () #push-options "--z3rlimit 150" val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a))) let rec map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g n inp f acc0 = let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_sh = f_shift blocksize mi hi_f hi_g f in let f_map = map_blocks_f #a blocksize hi_g inp f_sh in let lp = Loops.repeat_right mi (mi + n) a_f f_gen acc0 in let rp = Loops.repeat_right 0 n a_g f_map (Seq.empty #a) in if n = 0 then begin Loops.eq_repeat_right mi (mi + n) a_f f_gen acc0; Loops.eq_repeat_right 0 n a_g f_map (Seq.empty #a); Seq.Base.append_empty_r acc0 end else begin let lp1 = Loops.repeat_right mi (mi + n - 1) a_f f_gen acc0 in let rp1 = Loops.repeat_right 0 (n - 1) a_g f_map (Seq.empty #a) in let block = Seq.slice inp ((n - 1) * blocksize) (n * blocksize) in Loops.unfold_repeat_right 0 n a_g f_map (Seq.empty #a) (n - 1); assert (rp == f_map (n - 1) rp1); assert (rp == Seq.append rp1 (f (mi + n - 1) block)); calc (==) { Loops.repeat_right mi (mi + n) a_f f_gen acc0; (==) { Loops.unfold_repeat_right mi (mi + n) a_f f_gen acc0 (mi + n - 1) } Seq.append lp1 (f (mi + n - 1) block); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g (n - 1) inp f acc0 } Seq.append (Seq.append acc0 rp1) (f (mi + n - 1) block); (==) { Seq.Base.append_assoc acc0 rp1 (f (mi + n - 1) block) } Seq.append acc0 (Seq.append rp1 (f (mi + n - 1) block)); } end #pop-options let map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n inp f acc0 = let f_map = repeat_gen_blocks_map_f blocksize hi f in let a_map = map_blocks_a a blocksize hi in let f_gen = repeat_gen_blocks_f blocksize mi hi n inp a_map f_map in let f_map_s = f_shift blocksize mi hi n f in let a_map_s = map_blocks_a a blocksize n in let f_gen_s = map_blocks_f #a blocksize n inp f_map_s in calc (==) { Seq.append acc0 (map_blocks_multi blocksize n n inp f_map_s); (==) { lemma_map_blocks_multi blocksize n n inp f_map_s } Seq.append acc0 (Loops.repeat_gen n a_map_s f_gen_s (Seq.empty #a)); (==) { Loops.repeat_gen_def n a_map_s f_gen_s (Seq.empty #a) } Seq.append acc0 (Loops.repeat_right 0 n a_map_s f_gen_s (Seq.empty #a)); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi n n inp f acc0 } Loops.repeat_right mi (mi + n) a_map f_gen acc0; (==) { } map_blocks_multi_acc #a blocksize mi hi n inp f acc0; } let map_blocks_acc_is_map_blocks #a blocksize mi hi inp f l acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.cancel_mul_div n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let f_sh = f_shift blocksize mi hi n f in let l_sh = l_shift blocksize mi hi n l in lemma_map_blocks #a blocksize inp f_sh l_sh; map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n blocks f acc0 let map_blocks_multi_acc_is_map_blocks_multi0 #a blocksize hi n inp f = let f_sh = f_shift blocksize 0 hi n f in let a_map = map_blocks_a a blocksize n in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi_acc blocksize 0 hi n inp f Seq.empty; (==) { map_blocks_multi_acc_is_map_blocks_multi #a blocksize 0 hi n inp f Seq.empty } Seq.append Seq.empty (map_blocks_multi blocksize n n inp f_sh); (==) { Seq.Base.append_empty_l (map_blocks_multi blocksize n n inp f_sh) } map_blocks_multi blocksize n n inp f_sh; (==) { map_blocks_multi_extensionality blocksize n n inp f_sh f } map_blocks_multi blocksize n n inp f; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_acc_is_map_blocks0: #a:Type0 -> blocksize:size_pos -> hi:nat -> inp:seq a{length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> Lemma (map_blocks_acc #a blocksize 0 hi inp f l Seq.empty `Seq.equal` map_blocks #a blocksize inp f l)
[]
Lib.Sequence.Lemmas.map_blocks_acc_is_map_blocks0
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> hi: Prims.nat -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp / blocksize <= hi} -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> l: (i: Prims.nat{i <= hi} -> rem: Prims.nat{rem < blocksize} -> _: Lib.Sequence.lseq a rem -> Lib.Sequence.lseq a rem) -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (Lib.Sequence.Lemmas.map_blocks_acc blocksize 0 hi inp f l FStar.Seq.Base.empty) (Lib.Sequence.map_blocks blocksize inp f l))
{ "end_col": 5, "end_line": 783, "start_col": 59, "start_line": 769 }
FStar.Pervasives.Lemma
val repeat_gen_blocks_multi_extensionality_zero: #inp_t:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + n <= hi_f /\ n <= hi_g} -> inp:seq inp_t{length inp == n * blocksize} -> a_f:(i:nat{i <= hi_f} -> Type) -> a_g:(i:nat{i <= hi_g} -> Type) -> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a_f i -> a_f (i + 1)) -> g:(i:nat{i < hi_g} -> lseq inp_t blocksize -> a_g i -> a_g (i + 1)) -> acc0:a_f mi -> Lemma (requires (forall (i:nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i:nat{i < n}) (block:lseq inp_t blocksize) (acc:a_f (mi + i)). f (mi + i) block acc == g i block acc)) (ensures repeat_gen_blocks_multi blocksize mi hi_f n inp a_f f acc0 == repeat_gen_blocks_multi blocksize 0 hi_g n inp a_g g acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0
val repeat_gen_blocks_multi_extensionality_zero: #inp_t:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + n <= hi_f /\ n <= hi_g} -> inp:seq inp_t{length inp == n * blocksize} -> a_f:(i:nat{i <= hi_f} -> Type) -> a_g:(i:nat{i <= hi_g} -> Type) -> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a_f i -> a_f (i + 1)) -> g:(i:nat{i < hi_g} -> lseq inp_t blocksize -> a_g i -> a_g (i + 1)) -> acc0:a_f mi -> Lemma (requires (forall (i:nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i:nat{i < n}) (block:lseq inp_t blocksize) (acc:a_f (mi + i)). f (mi + i) block acc == g i block acc)) (ensures repeat_gen_blocks_multi blocksize mi hi_f n inp a_f f acc0 == repeat_gen_blocks_multi blocksize 0 hi_g n inp a_g g acc0) let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 =
false
null
true
let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.Lemmas.repeat_gen_right_extensionality", "Lib.Sequence.Lemmas.repeat_gen_blocks_f", "Prims.unit" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = ()
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_blocks_multi_extensionality_zero: #inp_t:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + n <= hi_f /\ n <= hi_g} -> inp:seq inp_t{length inp == n * blocksize} -> a_f:(i:nat{i <= hi_f} -> Type) -> a_g:(i:nat{i <= hi_g} -> Type) -> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a_f i -> a_f (i + 1)) -> g:(i:nat{i < hi_g} -> lseq inp_t blocksize -> a_g i -> a_g (i + 1)) -> acc0:a_f mi -> Lemma (requires (forall (i:nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i:nat{i < n}) (block:lseq inp_t blocksize) (acc:a_f (mi + i)). f (mi + i) block acc == g i block acc)) (ensures repeat_gen_blocks_multi blocksize mi hi_f n inp a_f f acc0 == repeat_gen_blocks_multi blocksize 0 hi_g n inp a_g g acc0)
[]
Lib.Sequence.Lemmas.repeat_gen_blocks_multi_extensionality_zero
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi_f: Prims.nat -> hi_g: Prims.nat -> n: Prims.nat{mi + n <= hi_f /\ n <= hi_g} -> inp: Lib.Sequence.seq inp_t {Lib.Sequence.length inp == n * blocksize} -> a_f: (i: Prims.nat{i <= hi_f} -> Type) -> a_g: (i: Prims.nat{i <= hi_g} -> Type) -> f: (i: Prims.nat{i < hi_f} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a_f i -> a_f (i + 1)) -> g: (i: Prims.nat{i < hi_g} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a_g i -> a_g (i + 1)) -> acc0: a_f mi -> FStar.Pervasives.Lemma (requires (forall (i: Prims.nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i: Prims.nat{i < n}) (block: Lib.Sequence.lseq inp_t blocksize) (acc: a_f (mi + i)). f (mi + i) block acc == g i block acc)) (ensures Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize mi hi_f n inp a_f f acc0 == Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize 0 hi_g n inp a_g g acc0)
{ "end_col": 63, "end_line": 87, "start_col": 102, "start_line": 84 }
FStar.Pervasives.Lemma
val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc)
[ { "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": 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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc)
val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc =
false
null
true
let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc)
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.l_and", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Prims.op_Division", "Prims._assert", "Prims.unit", "FStar.Seq.Properties.slice_slice", "FStar.Math.Lemmas.lemma_mult_le_right", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "Lib.Sequence.Lemmas.repeat_gen_blocks_f", "Lib.Sequence.Lemmas.split_len_lemma0" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc)
[]
Lib.Sequence.Lemmas.aux_repeat_bf_s0
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize == 0} -> mi: Prims.nat -> hi: Prims.nat -> n: Prims.nat{mi + n <= hi} -> inp: Lib.Sequence.seq inp_t {len0 <= Lib.Sequence.length inp /\ Lib.Sequence.length inp == n * blocksize} -> a: (i: Prims.nat{i <= hi} -> Type) -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) -> i: Prims.nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} -> acc: a i -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in let n0 = len0 / blocksize in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma0 blocksize n len0 in let t0 = FStar.Seq.Base.slice inp 0 len0 in let repeat_bf_s0 = Lib.Sequence.Lemmas.repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = Lib.Sequence.Lemmas.repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc))
{ "end_col": 46, "end_line": 205, "start_col": 66, "start_line": 189 }
FStar.Pervasives.Lemma
val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1)
[ { "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": 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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0
val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 =
false
null
true
let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Lib.Sequence.seq", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Prims.op_Division", "Lib.Sequence.length", "Prims.op_Addition", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi_split", "Prims.unit", "Lib.Sequence.Lemmas.split_len_lemma0", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.Sequence.Lemmas.split_len_lemma" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1)
[]
Lib.Sequence.Lemmas.repeat_gen_blocks_multi_split_slice
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize == 0} -> mi: Prims.nat -> hi: Prims.nat -> inp: Lib.Sequence.seq inp_t { len0 <= (Lib.Sequence.length inp / blocksize) * blocksize /\ mi + Lib.Sequence.length inp / blocksize <= hi } -> a: (i: Prims.nat{i <= hi} -> Type) -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) -> acc0: a mi -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma blocksize len len0 in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma0 blocksize n len0 in let blocks = FStar.Seq.Base.slice inp 0 (n * blocksize) in let t0 = FStar.Seq.Base.slice inp 0 len0 in let t1 = FStar.Seq.Base.slice inp len0 (n * blocksize) in let acc1 = Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1))
{ "end_col": 70, "end_line": 347, "start_col": 82, "start_line": 341 }
FStar.Pervasives.Lemma
val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len)
[ { "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": 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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1
val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp =
false
null
true
let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc ( == ) { len0 + n1 * blocksize; ( == ) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; ( == ) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; ( == ) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Lib.Sequence.seq", "Prims.op_LessThanOrEqual", "Lib.Sequence.length", "FStar.Seq.Properties.slice_slice", "FStar.Mul.op_Star", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Prims.unit", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Prims.op_Subtraction", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.len0_div_bs", "Prims.squash", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.div_exact_r", "Prims.op_Division" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len)
[]
Lib.Sequence.Lemmas.slice_slice_last
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize = 0} -> inp: Lib.Sequence.seq inp_t {len0 <= Lib.Sequence.length inp} -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = FStar.Seq.Base.slice inp len0 len in FStar.Seq.Base.equal (FStar.Seq.Base.slice t1 (n1 * blocksize) len1) (FStar.Seq.Base.slice inp (n * blocksize) len)))
{ "end_col": 52, "end_line": 382, "start_col": 48, "start_line": 364 }
FStar.Pervasives.Lemma
val map_blocks_multi_acc_is_map_blocks_multi0: #a:Type0 -> blocksize:size_pos -> hi:nat -> n:nat{n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> Lemma (map_blocks_multi_acc blocksize 0 hi n inp f Seq.empty `Seq.equal` map_blocks_multi blocksize n n inp f)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_multi_acc_is_map_blocks_multi0 #a blocksize hi n inp f = let f_sh = f_shift blocksize 0 hi n f in let a_map = map_blocks_a a blocksize n in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi_acc blocksize 0 hi n inp f Seq.empty; (==) { map_blocks_multi_acc_is_map_blocks_multi #a blocksize 0 hi n inp f Seq.empty } Seq.append Seq.empty (map_blocks_multi blocksize n n inp f_sh); (==) { Seq.Base.append_empty_l (map_blocks_multi blocksize n n inp f_sh) } map_blocks_multi blocksize n n inp f_sh; (==) { map_blocks_multi_extensionality blocksize n n inp f_sh f } map_blocks_multi blocksize n n inp f; }
val map_blocks_multi_acc_is_map_blocks_multi0: #a:Type0 -> blocksize:size_pos -> hi:nat -> n:nat{n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> Lemma (map_blocks_multi_acc blocksize 0 hi n inp f Seq.empty `Seq.equal` map_blocks_multi blocksize n n inp f) let map_blocks_multi_acc_is_map_blocks_multi0 #a blocksize hi n inp f =
false
null
true
let f_sh = f_shift blocksize 0 hi n f in let a_map = map_blocks_a a blocksize n in let acc0:a_map 0 = Seq.empty #a in calc ( == ) { map_blocks_multi_acc blocksize 0 hi n inp f Seq.empty; ( == ) { map_blocks_multi_acc_is_map_blocks_multi #a blocksize 0 hi n inp f Seq.empty } Seq.append Seq.empty (map_blocks_multi blocksize n n inp f_sh); ( == ) { Seq.Base.append_empty_l (map_blocks_multi blocksize n n inp f_sh) } map_blocks_multi blocksize n n inp f_sh; ( == ) { map_blocks_multi_extensionality blocksize n n inp f_sh f } map_blocks_multi blocksize n n inp f; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Prims.op_Addition", "FStar.Seq.Base.empty", "Lib.Sequence.Lemmas.map_blocks_multi_acc", "Lib.Sequence.map_blocks_multi", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Seq.Base.append", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.map_blocks_multi_acc_is_map_blocks_multi", "Prims.squash", "FStar.Seq.Base.append_empty_l", "Lib.Sequence.Lemmas.map_blocks_multi_extensionality", "Lib.Sequence.map_blocks_a", "Lib.Sequence.Lemmas.f_shift" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = () let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0 let map_blocks_acc #a blocksize mi hi inp f l acc0 = repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0 let map_blocks_acc_length #a blocksize mi hi inp f l acc0 = () let map_blocks_multi_acc_is_repeat_gen_blocks_multi #a blocksize mi hi n inp f acc0 = () let map_blocks_acc_is_repeat_gen_blocks #a blocksize mi hi inp f l acc0 = () #push-options "--z3rlimit 150" val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a))) let rec map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g n inp f acc0 = let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_sh = f_shift blocksize mi hi_f hi_g f in let f_map = map_blocks_f #a blocksize hi_g inp f_sh in let lp = Loops.repeat_right mi (mi + n) a_f f_gen acc0 in let rp = Loops.repeat_right 0 n a_g f_map (Seq.empty #a) in if n = 0 then begin Loops.eq_repeat_right mi (mi + n) a_f f_gen acc0; Loops.eq_repeat_right 0 n a_g f_map (Seq.empty #a); Seq.Base.append_empty_r acc0 end else begin let lp1 = Loops.repeat_right mi (mi + n - 1) a_f f_gen acc0 in let rp1 = Loops.repeat_right 0 (n - 1) a_g f_map (Seq.empty #a) in let block = Seq.slice inp ((n - 1) * blocksize) (n * blocksize) in Loops.unfold_repeat_right 0 n a_g f_map (Seq.empty #a) (n - 1); assert (rp == f_map (n - 1) rp1); assert (rp == Seq.append rp1 (f (mi + n - 1) block)); calc (==) { Loops.repeat_right mi (mi + n) a_f f_gen acc0; (==) { Loops.unfold_repeat_right mi (mi + n) a_f f_gen acc0 (mi + n - 1) } Seq.append lp1 (f (mi + n - 1) block); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g (n - 1) inp f acc0 } Seq.append (Seq.append acc0 rp1) (f (mi + n - 1) block); (==) { Seq.Base.append_assoc acc0 rp1 (f (mi + n - 1) block) } Seq.append acc0 (Seq.append rp1 (f (mi + n - 1) block)); } end #pop-options let map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n inp f acc0 = let f_map = repeat_gen_blocks_map_f blocksize hi f in let a_map = map_blocks_a a blocksize hi in let f_gen = repeat_gen_blocks_f blocksize mi hi n inp a_map f_map in let f_map_s = f_shift blocksize mi hi n f in let a_map_s = map_blocks_a a blocksize n in let f_gen_s = map_blocks_f #a blocksize n inp f_map_s in calc (==) { Seq.append acc0 (map_blocks_multi blocksize n n inp f_map_s); (==) { lemma_map_blocks_multi blocksize n n inp f_map_s } Seq.append acc0 (Loops.repeat_gen n a_map_s f_gen_s (Seq.empty #a)); (==) { Loops.repeat_gen_def n a_map_s f_gen_s (Seq.empty #a) } Seq.append acc0 (Loops.repeat_right 0 n a_map_s f_gen_s (Seq.empty #a)); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi n n inp f acc0 } Loops.repeat_right mi (mi + n) a_map f_gen acc0; (==) { } map_blocks_multi_acc #a blocksize mi hi n inp f acc0; } let map_blocks_acc_is_map_blocks #a blocksize mi hi inp f l acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.cancel_mul_div n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let f_sh = f_shift blocksize mi hi n f in let l_sh = l_shift blocksize mi hi n l in lemma_map_blocks #a blocksize inp f_sh l_sh; map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n blocks f acc0
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_multi_acc_is_map_blocks_multi0: #a:Type0 -> blocksize:size_pos -> hi:nat -> n:nat{n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> Lemma (map_blocks_multi_acc blocksize 0 hi n inp f Seq.empty `Seq.equal` map_blocks_multi blocksize n n inp f)
[]
Lib.Sequence.Lemmas.map_blocks_multi_acc_is_map_blocks_multi0
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> hi: Prims.nat -> n: Prims.nat{n <= hi} -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp == n * blocksize} -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (Lib.Sequence.Lemmas.map_blocks_multi_acc blocksize 0 hi n inp f FStar.Seq.Base.empty) (Lib.Sequence.map_blocks_multi blocksize n n inp f))
{ "end_col": 5, "end_line": 766, "start_col": 71, "start_line": 753 }
FStar.Pervasives.Lemma
val repeat_gen_right_extensionality: n:nat -> lo_g:nat -> a_f:(i:nat{i <= n} -> Type) -> a_g:(i:nat{lo_g <= i /\ i <= lo_g + n} -> Type) -> f:(i:nat{i < n} -> a_f i -> a_f (i + 1)) -> g:(i:nat{lo_g <= i /\ i < lo_g + n} -> a_g i -> a_g (i + 1)) -> acc0:a_f 0 -> Lemma (requires (forall (i:nat{i <= n}). a_f i == a_g (lo_g + i)) /\ (forall (i:nat{i < n}) (acc:a_f i). f i acc == g (lo_g + i) acc)) (ensures Loops.repeat_right 0 n a_f f acc0 == Loops.repeat_right lo_g (lo_g + n) a_g g acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end
val repeat_gen_right_extensionality: n:nat -> lo_g:nat -> a_f:(i:nat{i <= n} -> Type) -> a_g:(i:nat{lo_g <= i /\ i <= lo_g + n} -> Type) -> f:(i:nat{i < n} -> a_f i -> a_f (i + 1)) -> g:(i:nat{lo_g <= i /\ i < lo_g + n} -> a_g i -> a_g (i + 1)) -> acc0:a_f 0 -> Lemma (requires (forall (i:nat{i <= n}). a_f i == a_g (lo_g + i)) /\ (forall (i:nat{i < n}) (acc:a_f i). f i acc == g (lo_g + i) acc)) (ensures Loops.repeat_right 0 n a_f f acc0 == Loops.repeat_right lo_g (lo_g + n) a_g g acc0) let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 =
false
null
true
if n = 0 then (Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g + n) a_g g acc0) else (Loops.unfold_repeat_right 0 n a_f f acc0 (n - 1); Loops.unfold_repeat_right lo_g (lo_g + n) a_g g acc0 (lo_g + n - 1); repeat_gen_right_extensionality (n - 1) lo_g a_f a_g f g acc0)
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_and", "Prims.op_Addition", "Prims.op_LessThan", "Prims.op_Equality", "Prims.int", "Lib.LoopCombinators.eq_repeat_right", "Prims.unit", "Prims.bool", "Lib.Sequence.Lemmas.repeat_gen_right_extensionality", "Prims.op_Subtraction", "Lib.LoopCombinators.unfold_repeat_right" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_right_extensionality: n:nat -> lo_g:nat -> a_f:(i:nat{i <= n} -> Type) -> a_g:(i:nat{lo_g <= i /\ i <= lo_g + n} -> Type) -> f:(i:nat{i < n} -> a_f i -> a_f (i + 1)) -> g:(i:nat{lo_g <= i /\ i < lo_g + n} -> a_g i -> a_g (i + 1)) -> acc0:a_f 0 -> Lemma (requires (forall (i:nat{i <= n}). a_f i == a_g (lo_g + i)) /\ (forall (i:nat{i < n}) (acc:a_f i). f i acc == g (lo_g + i) acc)) (ensures Loops.repeat_right 0 n a_f f acc0 == Loops.repeat_right lo_g (lo_g + n) a_g g acc0)
[ "recursion" ]
Lib.Sequence.Lemmas.repeat_gen_right_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Prims.nat -> lo_g: Prims.nat -> a_f: (i: Prims.nat{i <= n} -> Type) -> a_g: (i: Prims.nat{lo_g <= i /\ i <= lo_g + n} -> Type) -> f: (i: Prims.nat{i < n} -> _: a_f i -> a_f (i + 1)) -> g: (i: Prims.nat{lo_g <= i /\ i < lo_g + n} -> _: a_g i -> a_g (i + 1)) -> acc0: a_f 0 -> FStar.Pervasives.Lemma (requires (forall (i: Prims.nat{i <= n}). a_f i == a_g (lo_g + i)) /\ (forall (i: Prims.nat{i < n}) (acc: a_f i). f i acc == g (lo_g + i) acc)) (ensures Lib.LoopCombinators.repeat_right 0 n a_f f acc0 == Lib.LoopCombinators.repeat_right lo_g (lo_g + n) a_g g acc0)
{ "end_col": 67, "end_line": 39, "start_col": 2, "start_line": 33 }
FStar.Pervasives.Lemma
val map_blocks_multi_acc_is_map_blocks_multi: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi mi -> Lemma (map_blocks_multi_acc blocksize mi hi n inp f acc0 `Seq.equal` Seq.append acc0 (map_blocks_multi blocksize n n inp (f_shift blocksize mi hi n f)))
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n inp f acc0 = let f_map = repeat_gen_blocks_map_f blocksize hi f in let a_map = map_blocks_a a blocksize hi in let f_gen = repeat_gen_blocks_f blocksize mi hi n inp a_map f_map in let f_map_s = f_shift blocksize mi hi n f in let a_map_s = map_blocks_a a blocksize n in let f_gen_s = map_blocks_f #a blocksize n inp f_map_s in calc (==) { Seq.append acc0 (map_blocks_multi blocksize n n inp f_map_s); (==) { lemma_map_blocks_multi blocksize n n inp f_map_s } Seq.append acc0 (Loops.repeat_gen n a_map_s f_gen_s (Seq.empty #a)); (==) { Loops.repeat_gen_def n a_map_s f_gen_s (Seq.empty #a) } Seq.append acc0 (Loops.repeat_right 0 n a_map_s f_gen_s (Seq.empty #a)); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi n n inp f acc0 } Loops.repeat_right mi (mi + n) a_map f_gen acc0; (==) { } map_blocks_multi_acc #a blocksize mi hi n inp f acc0; }
val map_blocks_multi_acc_is_map_blocks_multi: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi mi -> Lemma (map_blocks_multi_acc blocksize mi hi n inp f acc0 `Seq.equal` Seq.append acc0 (map_blocks_multi blocksize n n inp (f_shift blocksize mi hi n f))) let map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n inp f acc0 =
false
null
true
let f_map = repeat_gen_blocks_map_f blocksize hi f in let a_map = map_blocks_a a blocksize hi in let f_gen = repeat_gen_blocks_f blocksize mi hi n inp a_map f_map in let f_map_s = f_shift blocksize mi hi n f in let a_map_s = map_blocks_a a blocksize n in let f_gen_s = map_blocks_f #a blocksize n inp f_map_s in calc ( == ) { Seq.append acc0 (map_blocks_multi blocksize n n inp f_map_s); ( == ) { lemma_map_blocks_multi blocksize n n inp f_map_s } Seq.append acc0 (Loops.repeat_gen n a_map_s f_gen_s (Seq.empty #a)); ( == ) { Loops.repeat_gen_def n a_map_s f_gen_s (Seq.empty #a) } Seq.append acc0 (Loops.repeat_right 0 n a_map_s f_gen_s (Seq.empty #a)); ( == ) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi n n inp f acc0 } Loops.repeat_right mi (mi + n) a_map f_gen acc0; ( == ) { () } map_blocks_multi_acc #a blocksize mi hi n inp f acc0; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.map_blocks_a", "FStar.Calc.calc_finish", "FStar.Seq.Base.seq", "FStar.Seq.Base.append", "Lib.Sequence.map_blocks_multi", "Lib.Sequence.Lemmas.map_blocks_multi_acc", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.LoopCombinators.repeat_right", "FStar.Seq.Base.empty", "Lib.LoopCombinators.repeat_gen", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.lemma_map_blocks_multi", "Prims.squash", "Lib.LoopCombinators.repeat_gen_def", "Lib.Sequence.Lemmas.map_blocks_multi_acc_is_map_blocks_multi_", "Lib.Sequence.map_blocks_f", "Lib.Sequence.Lemmas.f_shift", "Prims.l_and", "Lib.Sequence.Lemmas.repeat_gen_blocks_f", "Lib.Sequence.Lemmas.repeat_gen_blocks_map_f" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = () let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0 let map_blocks_acc #a blocksize mi hi inp f l acc0 = repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0 let map_blocks_acc_length #a blocksize mi hi inp f l acc0 = () let map_blocks_multi_acc_is_repeat_gen_blocks_multi #a blocksize mi hi n inp f acc0 = () let map_blocks_acc_is_repeat_gen_blocks #a blocksize mi hi inp f l acc0 = () #push-options "--z3rlimit 150" val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a))) let rec map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g n inp f acc0 = let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_sh = f_shift blocksize mi hi_f hi_g f in let f_map = map_blocks_f #a blocksize hi_g inp f_sh in let lp = Loops.repeat_right mi (mi + n) a_f f_gen acc0 in let rp = Loops.repeat_right 0 n a_g f_map (Seq.empty #a) in if n = 0 then begin Loops.eq_repeat_right mi (mi + n) a_f f_gen acc0; Loops.eq_repeat_right 0 n a_g f_map (Seq.empty #a); Seq.Base.append_empty_r acc0 end else begin let lp1 = Loops.repeat_right mi (mi + n - 1) a_f f_gen acc0 in let rp1 = Loops.repeat_right 0 (n - 1) a_g f_map (Seq.empty #a) in let block = Seq.slice inp ((n - 1) * blocksize) (n * blocksize) in Loops.unfold_repeat_right 0 n a_g f_map (Seq.empty #a) (n - 1); assert (rp == f_map (n - 1) rp1); assert (rp == Seq.append rp1 (f (mi + n - 1) block)); calc (==) { Loops.repeat_right mi (mi + n) a_f f_gen acc0; (==) { Loops.unfold_repeat_right mi (mi + n) a_f f_gen acc0 (mi + n - 1) } Seq.append lp1 (f (mi + n - 1) block); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g (n - 1) inp f acc0 } Seq.append (Seq.append acc0 rp1) (f (mi + n - 1) block); (==) { Seq.Base.append_assoc acc0 rp1 (f (mi + n - 1) block) } Seq.append acc0 (Seq.append rp1 (f (mi + n - 1) block)); } end #pop-options
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_multi_acc_is_map_blocks_multi: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq a{length inp == n * blocksize} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi mi -> Lemma (map_blocks_multi_acc blocksize mi hi n inp f acc0 `Seq.equal` Seq.append acc0 (map_blocks_multi blocksize n n inp (f_shift blocksize mi hi n f)))
[]
Lib.Sequence.Lemmas.map_blocks_multi_acc_is_map_blocks_multi
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi: Prims.nat -> n: Prims.nat{mi + n <= hi} -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp == n * blocksize} -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> acc0: Lib.Sequence.map_blocks_a a blocksize hi mi -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (Lib.Sequence.Lemmas.map_blocks_multi_acc blocksize mi hi n inp f acc0) (FStar.Seq.Base.append acc0 (Lib.Sequence.map_blocks_multi blocksize n n inp (Lib.Sequence.Lemmas.f_shift blocksize mi hi n f))))
{ "end_col": 3, "end_line": 738, "start_col": 78, "start_line": 719 }
FStar.Pervasives.Lemma
val map_blocks_acc_is_map_blocks: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq a{mi + length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> acc0:map_blocks_a a blocksize hi mi -> Lemma (let n = length inp / blocksize in map_blocks_acc #a blocksize mi hi inp f l acc0 `Seq.equal` Seq.append acc0 (map_blocks #a blocksize inp (f_shift blocksize mi hi n f) (l_shift blocksize mi hi n l)))
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_acc_is_map_blocks #a blocksize mi hi inp f l acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.cancel_mul_div n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let f_sh = f_shift blocksize mi hi n f in let l_sh = l_shift blocksize mi hi n l in lemma_map_blocks #a blocksize inp f_sh l_sh; map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n blocks f acc0
val map_blocks_acc_is_map_blocks: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq a{mi + length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> acc0:map_blocks_a a blocksize hi mi -> Lemma (let n = length inp / blocksize in map_blocks_acc #a blocksize mi hi inp f l acc0 `Seq.equal` Seq.append acc0 (map_blocks #a blocksize inp (f_shift blocksize mi hi n f) (l_shift blocksize mi hi n l))) let map_blocks_acc_is_map_blocks #a blocksize mi hi inp f l acc0 =
false
null
true
let len = length inp in let n = len / blocksize in Math.Lemmas.cancel_mul_div n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let f_sh = f_shift blocksize mi hi n f in let l_sh = l_shift blocksize mi hi n l in lemma_map_blocks #a blocksize inp f_sh l_sh; map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n blocks f acc0
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Lib.Sequence.seq", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Prims.op_Division", "Lib.Sequence.length", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.map_blocks_a", "Lib.Sequence.Lemmas.map_blocks_multi_acc_is_map_blocks_multi", "Prims.unit", "Lib.Sequence.lemma_map_blocks", "Lib.Sequence.Lemmas.l_shift", "Lib.Sequence.Lemmas.f_shift", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "FStar.Math.Lemmas.cancel_mul_div", "Prims.int" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = () let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0 let map_blocks_acc #a blocksize mi hi inp f l acc0 = repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0 let map_blocks_acc_length #a blocksize mi hi inp f l acc0 = () let map_blocks_multi_acc_is_repeat_gen_blocks_multi #a blocksize mi hi n inp f acc0 = () let map_blocks_acc_is_repeat_gen_blocks #a blocksize mi hi inp f l acc0 = () #push-options "--z3rlimit 150" val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a))) let rec map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g n inp f acc0 = let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_sh = f_shift blocksize mi hi_f hi_g f in let f_map = map_blocks_f #a blocksize hi_g inp f_sh in let lp = Loops.repeat_right mi (mi + n) a_f f_gen acc0 in let rp = Loops.repeat_right 0 n a_g f_map (Seq.empty #a) in if n = 0 then begin Loops.eq_repeat_right mi (mi + n) a_f f_gen acc0; Loops.eq_repeat_right 0 n a_g f_map (Seq.empty #a); Seq.Base.append_empty_r acc0 end else begin let lp1 = Loops.repeat_right mi (mi + n - 1) a_f f_gen acc0 in let rp1 = Loops.repeat_right 0 (n - 1) a_g f_map (Seq.empty #a) in let block = Seq.slice inp ((n - 1) * blocksize) (n * blocksize) in Loops.unfold_repeat_right 0 n a_g f_map (Seq.empty #a) (n - 1); assert (rp == f_map (n - 1) rp1); assert (rp == Seq.append rp1 (f (mi + n - 1) block)); calc (==) { Loops.repeat_right mi (mi + n) a_f f_gen acc0; (==) { Loops.unfold_repeat_right mi (mi + n) a_f f_gen acc0 (mi + n - 1) } Seq.append lp1 (f (mi + n - 1) block); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g (n - 1) inp f acc0 } Seq.append (Seq.append acc0 rp1) (f (mi + n - 1) block); (==) { Seq.Base.append_assoc acc0 rp1 (f (mi + n - 1) block) } Seq.append acc0 (Seq.append rp1 (f (mi + n - 1) block)); } end #pop-options let map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n inp f acc0 = let f_map = repeat_gen_blocks_map_f blocksize hi f in let a_map = map_blocks_a a blocksize hi in let f_gen = repeat_gen_blocks_f blocksize mi hi n inp a_map f_map in let f_map_s = f_shift blocksize mi hi n f in let a_map_s = map_blocks_a a blocksize n in let f_gen_s = map_blocks_f #a blocksize n inp f_map_s in calc (==) { Seq.append acc0 (map_blocks_multi blocksize n n inp f_map_s); (==) { lemma_map_blocks_multi blocksize n n inp f_map_s } Seq.append acc0 (Loops.repeat_gen n a_map_s f_gen_s (Seq.empty #a)); (==) { Loops.repeat_gen_def n a_map_s f_gen_s (Seq.empty #a) } Seq.append acc0 (Loops.repeat_right 0 n a_map_s f_gen_s (Seq.empty #a)); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi n n inp f acc0 } Loops.repeat_right mi (mi + n) a_map f_gen acc0; (==) { } map_blocks_multi_acc #a blocksize mi hi n inp f acc0; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_acc_is_map_blocks: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi:nat -> inp:seq a{mi + length inp / blocksize <= hi} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> acc0:map_blocks_a a blocksize hi mi -> Lemma (let n = length inp / blocksize in map_blocks_acc #a blocksize mi hi inp f l acc0 `Seq.equal` Seq.append acc0 (map_blocks #a blocksize inp (f_shift blocksize mi hi n f) (l_shift blocksize mi hi n l)))
[]
Lib.Sequence.Lemmas.map_blocks_acc_is_map_blocks
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi: Prims.nat -> inp: Lib.Sequence.seq a {mi + Lib.Sequence.length inp / blocksize <= hi} -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> l: (i: Prims.nat{i <= hi} -> rem: Prims.nat{rem < blocksize} -> _: Lib.Sequence.lseq a rem -> Lib.Sequence.lseq a rem) -> acc0: Lib.Sequence.map_blocks_a a blocksize hi mi -> FStar.Pervasives.Lemma (ensures (let n = Lib.Sequence.length inp / blocksize in FStar.Seq.Base.equal (Lib.Sequence.Lemmas.map_blocks_acc blocksize mi hi inp f l acc0) (FStar.Seq.Base.append acc0 (Lib.Sequence.map_blocks blocksize inp (Lib.Sequence.Lemmas.f_shift blocksize mi hi n f) (Lib.Sequence.Lemmas.l_shift blocksize mi hi n l)))))
{ "end_col": 77, "end_line": 750, "start_col": 66, "start_line": 741 }
FStar.Pervasives.Lemma
val repeat_right_extensionality: n:nat -> lo:nat -> a_f:(i:nat{lo <= i /\ i <= lo + n} -> Type) -> a_g:(i:nat{lo <= i /\ i <= lo + n} -> Type) -> f:(i:nat{lo <= i /\ i < lo + n} -> a_f i -> a_f (i + 1)) -> g:(i:nat{lo <= i /\ i < lo + n} -> a_g i -> a_g (i + 1)) -> acc0:a_f lo -> Lemma (requires (forall (i:nat{lo <= i /\ i <= lo + n}). a_f i == a_g i) /\ (forall (i:nat{lo <= i /\ i < lo + n}) (acc:a_f i). f i acc == g i acc)) (ensures Loops.repeat_right lo (lo + n) a_f f acc0 == Loops.repeat_right lo (lo + n) a_g g acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end
val repeat_right_extensionality: n:nat -> lo:nat -> a_f:(i:nat{lo <= i /\ i <= lo + n} -> Type) -> a_g:(i:nat{lo <= i /\ i <= lo + n} -> Type) -> f:(i:nat{lo <= i /\ i < lo + n} -> a_f i -> a_f (i + 1)) -> g:(i:nat{lo <= i /\ i < lo + n} -> a_g i -> a_g (i + 1)) -> acc0:a_f lo -> Lemma (requires (forall (i:nat{lo <= i /\ i <= lo + n}). a_f i == a_g i) /\ (forall (i:nat{lo <= i /\ i < lo + n}) (acc:a_f i). f i acc == g i acc)) (ensures Loops.repeat_right lo (lo + n) a_f f acc0 == Loops.repeat_right lo (lo + n) a_g g acc0) let rec repeat_right_extensionality n lo a_f a_g f g acc0 =
false
null
true
if n = 0 then (Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0) else (Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0)
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Prims.op_LessThan", "Prims.op_Equality", "Prims.int", "Lib.LoopCombinators.eq_repeat_right", "Prims.unit", "Prims.bool", "Lib.Sequence.Lemmas.repeat_right_extensionality", "Prims.op_Subtraction", "Lib.LoopCombinators.unfold_repeat_right" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_right_extensionality: n:nat -> lo:nat -> a_f:(i:nat{lo <= i /\ i <= lo + n} -> Type) -> a_g:(i:nat{lo <= i /\ i <= lo + n} -> Type) -> f:(i:nat{lo <= i /\ i < lo + n} -> a_f i -> a_f (i + 1)) -> g:(i:nat{lo <= i /\ i < lo + n} -> a_g i -> a_g (i + 1)) -> acc0:a_f lo -> Lemma (requires (forall (i:nat{lo <= i /\ i <= lo + n}). a_f i == a_g i) /\ (forall (i:nat{lo <= i /\ i < lo + n}) (acc:a_f i). f i acc == g i acc)) (ensures Loops.repeat_right lo (lo + n) a_f f acc0 == Loops.repeat_right lo (lo + n) a_g g acc0)
[ "recursion" ]
Lib.Sequence.Lemmas.repeat_right_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
n: Prims.nat -> lo: Prims.nat -> a_f: (i: Prims.nat{lo <= i /\ i <= lo + n} -> Type) -> a_g: (i: Prims.nat{lo <= i /\ i <= lo + n} -> Type) -> f: (i: Prims.nat{lo <= i /\ i < lo + n} -> _: a_f i -> a_f (i + 1)) -> g: (i: Prims.nat{lo <= i /\ i < lo + n} -> _: a_g i -> a_g (i + 1)) -> acc0: a_f lo -> FStar.Pervasives.Lemma (requires (forall (i: Prims.nat{lo <= i /\ i <= lo + n}). a_f i == a_g i) /\ (forall (i: Prims.nat{lo <= i /\ i < lo + n}) (acc: a_f i). f i acc == g i acc)) (ensures Lib.LoopCombinators.repeat_right lo (lo + n) a_f f acc0 == Lib.LoopCombinators.repeat_right lo (lo + n) a_g g acc0)
{ "end_col": 63, "end_line": 29, "start_col": 2, "start_line": 23 }
FStar.Pervasives.Lemma
val repeat_gen_blocks_extensionality_zero: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + n <= hi_f /\ n <= hi_g} -> inp:seq inp_t{n == length inp / blocksize} -> a_f:(i:nat{i <= hi_f} -> Type) -> a_g:(i:nat{i <= hi_g} -> Type) -> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a_f i -> a_f (i + 1)) -> l_f:(i:nat{i <= hi_f} -> len:nat{len < blocksize} -> lseq inp_t len -> a_f i -> c) -> g:(i:nat{i < hi_g} -> lseq inp_t blocksize -> a_g i -> a_g (i + 1)) -> l_g:(i:nat{i <= hi_g} -> len:nat{len < blocksize} -> lseq inp_t len -> a_g i -> c) -> acc0:a_f mi -> Lemma (requires (forall (i:nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i:nat{i < n}) (block:lseq inp_t blocksize) (acc:a_f (mi + i)). f (mi + i) block acc == g i block acc) /\ (forall (i:nat{i <= n}) (len:nat{len < blocksize}) (block:lseq inp_t len) (acc:a_f (mi + i)). l_f (mi + i) len block acc == l_g i len block acc)) (ensures repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0 == repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; }
val repeat_gen_blocks_extensionality_zero: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + n <= hi_f /\ n <= hi_g} -> inp:seq inp_t{n == length inp / blocksize} -> a_f:(i:nat{i <= hi_f} -> Type) -> a_g:(i:nat{i <= hi_g} -> Type) -> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a_f i -> a_f (i + 1)) -> l_f:(i:nat{i <= hi_f} -> len:nat{len < blocksize} -> lseq inp_t len -> a_f i -> c) -> g:(i:nat{i < hi_g} -> lseq inp_t blocksize -> a_g i -> a_g (i + 1)) -> l_g:(i:nat{i <= hi_g} -> len:nat{len < blocksize} -> lseq inp_t len -> a_g i -> c) -> acc0:a_f mi -> Lemma (requires (forall (i:nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i:nat{i < n}) (block:lseq inp_t blocksize) (acc:a_f (mi + i)). f (mi + i) block acc == g i block acc) /\ (forall (i:nat{i <= n}) (len:nat{len < blocksize}) (block:lseq inp_t len) (acc:a_f (mi + i)). l_f (mi + i) len block acc == l_g i len block acc)) (ensures repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0 == repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0) let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 =
false
null
true
let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc ( == ) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; ( == ) { () } l_f (mi + n) rem block_l acc_f; ( == ) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; ( == ) { () } l_g n rem block_l acc_g; ( == ) { () } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Prims.op_Division", "Lib.Sequence.length", "Prims.op_LessThan", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Lib.Sequence.Lemmas.repeat_gen_blocks", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi_extensionality_zero", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "FStar.Math.Lemmas.cancel_mul_mod", "FStar.Math.Lemmas.cancel_mul_div", "Prims.op_Modulus" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_blocks_extensionality_zero: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + n <= hi_f /\ n <= hi_g} -> inp:seq inp_t{n == length inp / blocksize} -> a_f:(i:nat{i <= hi_f} -> Type) -> a_g:(i:nat{i <= hi_g} -> Type) -> f:(i:nat{i < hi_f} -> lseq inp_t blocksize -> a_f i -> a_f (i + 1)) -> l_f:(i:nat{i <= hi_f} -> len:nat{len < blocksize} -> lseq inp_t len -> a_f i -> c) -> g:(i:nat{i < hi_g} -> lseq inp_t blocksize -> a_g i -> a_g (i + 1)) -> l_g:(i:nat{i <= hi_g} -> len:nat{len < blocksize} -> lseq inp_t len -> a_g i -> c) -> acc0:a_f mi -> Lemma (requires (forall (i:nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i:nat{i < n}) (block:lseq inp_t blocksize) (acc:a_f (mi + i)). f (mi + i) block acc == g i block acc) /\ (forall (i:nat{i <= n}) (len:nat{len < blocksize}) (block:lseq inp_t len) (acc:a_f (mi + i)). l_f (mi + i) len block acc == l_g i len block acc)) (ensures repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0 == repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0)
[]
Lib.Sequence.Lemmas.repeat_gen_blocks_extensionality_zero
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi_f: Prims.nat -> hi_g: Prims.nat -> n: Prims.nat{mi + n <= hi_f /\ n <= hi_g} -> inp: Lib.Sequence.seq inp_t {n == Lib.Sequence.length inp / blocksize} -> a_f: (i: Prims.nat{i <= hi_f} -> Type) -> a_g: (i: Prims.nat{i <= hi_g} -> Type) -> f: (i: Prims.nat{i < hi_f} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a_f i -> a_f (i + 1)) -> l_f: ( i: Prims.nat{i <= hi_f} -> len: Prims.nat{len < blocksize} -> _: Lib.Sequence.lseq inp_t len -> _: a_f i -> c) -> g: (i: Prims.nat{i < hi_g} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a_g i -> a_g (i + 1)) -> l_g: ( i: Prims.nat{i <= hi_g} -> len: Prims.nat{len < blocksize} -> _: Lib.Sequence.lseq inp_t len -> _: a_g i -> c) -> acc0: a_f mi -> FStar.Pervasives.Lemma (requires (forall (i: Prims.nat{i <= n}). a_f (mi + i) == a_g i) /\ (forall (i: Prims.nat{i < n}) (block: Lib.Sequence.lseq inp_t blocksize) (acc: a_f (mi + i)). f (mi + i) block acc == g i block acc) /\ (forall (i: Prims.nat{i <= n}) (len: Prims.nat{len < blocksize}) (block: Lib.Sequence.lseq inp_t len) (acc: a_f (mi + i)). l_f (mi + i) len block acc == l_g i len block acc)) (ensures Lib.Sequence.Lemmas.repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0 == Lib.Sequence.Lemmas.repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0)
{ "end_col": 5, "end_line": 110, "start_col": 107, "start_line": 90 }
FStar.Pervasives.Lemma
val map_blocks_is_empty: #a:Type0 -> blocksize:size_pos -> hi:nat -> inp:seq a{length inp == 0} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> Lemma (map_blocks #a blocksize inp f l == Seq.empty)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_is_empty #a blocksize hi inp f l = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in assert (rem == 0); calc (==) { map_blocks blocksize inp f l; (==) { lemma_map_blocks blocksize inp f l } map_blocks_multi #a blocksize nb nb blocks f; (==) { lemma_map_blocks_multi blocksize nb nb blocks f } Loops.repeat_gen nb (map_blocks_a a blocksize nb) (map_blocks_f #a blocksize nb inp f) Seq.empty; (==) { Loops.eq_repeat_gen0 nb (map_blocks_a a blocksize nb) (map_blocks_f #a blocksize nb inp f) Seq.empty } Seq.empty; }
val map_blocks_is_empty: #a:Type0 -> blocksize:size_pos -> hi:nat -> inp:seq a{length inp == 0} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> Lemma (map_blocks #a blocksize inp f l == Seq.empty) let map_blocks_is_empty #a blocksize hi inp f l =
false
null
true
let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in assert (rem == 0); calc ( == ) { map_blocks blocksize inp f l; ( == ) { lemma_map_blocks blocksize inp f l } map_blocks_multi #a blocksize nb nb blocks f; ( == ) { lemma_map_blocks_multi blocksize nb nb blocks f } Loops.repeat_gen nb (map_blocks_a a blocksize nb) (map_blocks_f #a blocksize nb inp f) Seq.empty; ( == ) { Loops.eq_repeat_gen0 nb (map_blocks_a a blocksize nb) (map_blocks_f #a blocksize nb inp f) Seq.empty } Seq.empty; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.lseq", "Prims.op_LessThanOrEqual", "FStar.Calc.calc_finish", "Lib.Sequence.map_blocks", "FStar.Seq.Base.empty", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.LoopCombinators.repeat_gen", "Lib.Sequence.map_blocks_a", "Lib.Sequence.map_blocks_f", "Lib.Sequence.map_blocks_multi", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.lemma_map_blocks", "Prims.squash", "Lib.Sequence.lemma_map_blocks_multi", "Lib.LoopCombinators.eq_repeat_gen0", "Prims._assert", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "Prims.op_Modulus", "Prims.op_Division" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = () let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0 let map_blocks_acc #a blocksize mi hi inp f l acc0 = repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0 let map_blocks_acc_length #a blocksize mi hi inp f l acc0 = () let map_blocks_multi_acc_is_repeat_gen_blocks_multi #a blocksize mi hi n inp f acc0 = () let map_blocks_acc_is_repeat_gen_blocks #a blocksize mi hi inp f l acc0 = () #push-options "--z3rlimit 150" val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a))) let rec map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g n inp f acc0 = let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_sh = f_shift blocksize mi hi_f hi_g f in let f_map = map_blocks_f #a blocksize hi_g inp f_sh in let lp = Loops.repeat_right mi (mi + n) a_f f_gen acc0 in let rp = Loops.repeat_right 0 n a_g f_map (Seq.empty #a) in if n = 0 then begin Loops.eq_repeat_right mi (mi + n) a_f f_gen acc0; Loops.eq_repeat_right 0 n a_g f_map (Seq.empty #a); Seq.Base.append_empty_r acc0 end else begin let lp1 = Loops.repeat_right mi (mi + n - 1) a_f f_gen acc0 in let rp1 = Loops.repeat_right 0 (n - 1) a_g f_map (Seq.empty #a) in let block = Seq.slice inp ((n - 1) * blocksize) (n * blocksize) in Loops.unfold_repeat_right 0 n a_g f_map (Seq.empty #a) (n - 1); assert (rp == f_map (n - 1) rp1); assert (rp == Seq.append rp1 (f (mi + n - 1) block)); calc (==) { Loops.repeat_right mi (mi + n) a_f f_gen acc0; (==) { Loops.unfold_repeat_right mi (mi + n) a_f f_gen acc0 (mi + n - 1) } Seq.append lp1 (f (mi + n - 1) block); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g (n - 1) inp f acc0 } Seq.append (Seq.append acc0 rp1) (f (mi + n - 1) block); (==) { Seq.Base.append_assoc acc0 rp1 (f (mi + n - 1) block) } Seq.append acc0 (Seq.append rp1 (f (mi + n - 1) block)); } end #pop-options let map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n inp f acc0 = let f_map = repeat_gen_blocks_map_f blocksize hi f in let a_map = map_blocks_a a blocksize hi in let f_gen = repeat_gen_blocks_f blocksize mi hi n inp a_map f_map in let f_map_s = f_shift blocksize mi hi n f in let a_map_s = map_blocks_a a blocksize n in let f_gen_s = map_blocks_f #a blocksize n inp f_map_s in calc (==) { Seq.append acc0 (map_blocks_multi blocksize n n inp f_map_s); (==) { lemma_map_blocks_multi blocksize n n inp f_map_s } Seq.append acc0 (Loops.repeat_gen n a_map_s f_gen_s (Seq.empty #a)); (==) { Loops.repeat_gen_def n a_map_s f_gen_s (Seq.empty #a) } Seq.append acc0 (Loops.repeat_right 0 n a_map_s f_gen_s (Seq.empty #a)); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi n n inp f acc0 } Loops.repeat_right mi (mi + n) a_map f_gen acc0; (==) { } map_blocks_multi_acc #a blocksize mi hi n inp f acc0; } let map_blocks_acc_is_map_blocks #a blocksize mi hi inp f l acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.cancel_mul_div n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let f_sh = f_shift blocksize mi hi n f in let l_sh = l_shift blocksize mi hi n l in lemma_map_blocks #a blocksize inp f_sh l_sh; map_blocks_multi_acc_is_map_blocks_multi #a blocksize mi hi n blocks f acc0 let map_blocks_multi_acc_is_map_blocks_multi0 #a blocksize hi n inp f = let f_sh = f_shift blocksize 0 hi n f in let a_map = map_blocks_a a blocksize n in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi_acc blocksize 0 hi n inp f Seq.empty; (==) { map_blocks_multi_acc_is_map_blocks_multi #a blocksize 0 hi n inp f Seq.empty } Seq.append Seq.empty (map_blocks_multi blocksize n n inp f_sh); (==) { Seq.Base.append_empty_l (map_blocks_multi blocksize n n inp f_sh) } map_blocks_multi blocksize n n inp f_sh; (==) { map_blocks_multi_extensionality blocksize n n inp f_sh f } map_blocks_multi blocksize n n inp f; } let map_blocks_acc_is_map_blocks0 #a blocksize hi inp f l = let len = length inp in let n = len / blocksize in let f_sh = f_shift blocksize 0 hi n f in let l_sh = l_shift blocksize 0 hi n l in calc (==) { map_blocks_acc #a blocksize 0 hi inp f l Seq.empty; (==) { map_blocks_acc_is_map_blocks blocksize 0 hi inp f l Seq.empty } Seq.append Seq.empty (map_blocks #a blocksize inp f_sh l_sh); (==) { Seq.Base.append_empty_l (map_blocks #a blocksize inp f_sh l_sh) } map_blocks #a blocksize inp f_sh l_sh; (==) { map_blocks_extensionality #a blocksize inp f l f_sh l_sh } map_blocks #a blocksize inp f l; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_is_empty: #a:Type0 -> blocksize:size_pos -> hi:nat -> inp:seq a{length inp == 0} -> f:(i:nat{i < hi} -> lseq a blocksize -> lseq a blocksize) -> l:(i:nat{i <= hi} -> rem:nat{rem < blocksize} -> lseq a rem -> lseq a rem) -> Lemma (map_blocks #a blocksize inp f l == Seq.empty)
[]
Lib.Sequence.Lemmas.map_blocks_is_empty
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> hi: Prims.nat -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp == 0} -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> l: (i: Prims.nat{i <= hi} -> rem: Prims.nat{rem < blocksize} -> _: Lib.Sequence.lseq a rem -> Lib.Sequence.lseq a rem) -> FStar.Pervasives.Lemma (ensures Lib.Sequence.map_blocks blocksize inp f l == FStar.Seq.Base.empty)
{ "end_col": 5, "end_line": 801, "start_col": 49, "start_line": 786 }
FStar.Pervasives.Lemma
val repeat_gen_blocks_split: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> hi:nat -> mi:nat{mi <= hi} -> inp:seq inp_t{len0 <= length inp /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> l:(i:nat{i <= hi} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c) -> acc0:a mi -> Lemma (let len = length inp in let n = len / blocksize in let n0 = len0 / blocksize in split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks blocksize mi hi inp a f l acc0 == repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; }
val repeat_gen_blocks_split: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> hi:nat -> mi:nat{mi <= hi} -> inp:seq inp_t{len0 <= length inp /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> l:(i:nat{i <= hi} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c) -> acc0:a mi -> Lemma (let len = length inp in let n = len / blocksize in let n0 = len0 / blocksize in split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks blocksize mi hi inp a f l acc0 == repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc) let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 =
false
null
true
let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc ( == ) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; ( == ) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc ( == ) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; ( == ) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; ( == ) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; ( == ) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.seq", "Prims.l_and", "Lib.Sequence.length", "Prims.op_Addition", "Prims.op_Division", "Prims.op_LessThan", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Lib.Sequence.Lemmas.repeat_gen_blocks", "FStar.Seq.Base.slice", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.len0_div_bs", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_sub_distr", "Lib.Sequence.Lemmas.slice_slice_last", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi_split_slice", "FStar.Math.Lemmas.cancel_mul_mod", "FStar.Seq.Base.seq", "Lib.Sequence.Lemmas.split_len_lemma0", "Lib.Sequence.Lemmas.split_len_lemma", "Lib.Sequence.Lemmas.len0_le_len_fraction", "Prims.op_Subtraction" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_blocks_split: #inp_t:Type0 -> #c:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> hi:nat -> mi:nat{mi <= hi} -> inp:seq inp_t{len0 <= length inp /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> l:(i:nat{i <= hi} -> len:nat{len < blocksize} -> lseq inp_t len -> a i -> c) -> acc0:a mi -> Lemma (let len = length inp in let n = len / blocksize in let n0 = len0 / blocksize in split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks blocksize mi hi inp a f l acc0 == repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc)
[]
Lib.Sequence.Lemmas.repeat_gen_blocks_split
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize == 0} -> hi: Prims.nat -> mi: Prims.nat{mi <= hi} -> inp: Lib.Sequence.seq inp_t {len0 <= Lib.Sequence.length inp /\ mi + Lib.Sequence.length inp / blocksize <= hi} -> a: (i: Prims.nat{i <= hi} -> Type) -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) -> l: ( i: Prims.nat{i <= hi} -> len: Prims.nat{len < blocksize} -> _: Lib.Sequence.lseq inp_t len -> _: a i -> c) -> acc0: a mi -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in let n = len / blocksize in let n0 = len0 / blocksize in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma blocksize len len0 in let t0 = FStar.Seq.Base.slice inp 0 len0 in let t1 = FStar.Seq.Base.slice inp len0 len in let acc = Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in Lib.Sequence.Lemmas.repeat_gen_blocks blocksize mi hi inp a f l acc0 == Lib.Sequence.Lemmas.repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc))
{ "end_col": 5, "end_line": 427, "start_col": 75, "start_line": 395 }
FStar.Pervasives.Lemma
val map_blocks_multi_extensionality: #a:Type0 -> blocksize:size_pos -> max:nat -> n:nat{n <= max} -> inp:seq a{length inp == max * blocksize} -> f:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) -> g:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) -> Lemma (requires (forall (i:nat{i < max}) (b_v:lseq a blocksize). f i b_v == g i b_v)) (ensures map_blocks_multi blocksize max n inp f == map_blocks_multi blocksize max n inp g)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; }
val map_blocks_multi_extensionality: #a:Type0 -> blocksize:size_pos -> max:nat -> n:nat{n <= max} -> inp:seq a{length inp == max * blocksize} -> f:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) -> g:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) -> Lemma (requires (forall (i:nat{i < max}) (b_v:lseq a blocksize). f i b_v == g i b_v)) (ensures map_blocks_multi blocksize max n inp f == map_blocks_multi blocksize max n inp g) let map_blocks_multi_extensionality #a blocksize max n inp f g =
false
null
true
let a_map = map_blocks_a a blocksize max in let acc0:a_map 0 = Seq.empty #a in calc ( == ) { map_blocks_multi blocksize max n inp f; ( == ) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; ( == ) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; ( == ) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; ( == ) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; ( == ) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Lib.Sequence.map_blocks_multi", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.LoopCombinators.repeat_gen", "Lib.Sequence.map_blocks_f", "Lib.LoopCombinators.repeat_right", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.lemma_map_blocks_multi", "Prims.squash", "Lib.LoopCombinators.repeat_gen_def", "Lib.Sequence.Lemmas.repeat_right_extensionality", "FStar.Seq.Base.empty", "Lib.Sequence.map_blocks_a" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties ////////////////////////
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_multi_extensionality: #a:Type0 -> blocksize:size_pos -> max:nat -> n:nat{n <= max} -> inp:seq a{length inp == max * blocksize} -> f:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) -> g:(i:nat{i < max} -> lseq a blocksize -> lseq a blocksize) -> Lemma (requires (forall (i:nat{i < max}) (b_v:lseq a blocksize). f i b_v == g i b_v)) (ensures map_blocks_multi blocksize max n inp f == map_blocks_multi blocksize max n inp g)
[]
Lib.Sequence.Lemmas.map_blocks_multi_extensionality
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> max: Prims.nat -> n: Prims.nat{n <= max} -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp == max * blocksize} -> f: (i: Prims.nat{i < max} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> g: (i: Prims.nat{i < max} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> FStar.Pervasives.Lemma (requires forall (i: Prims.nat{i < max}) (b_v: Lib.Sequence.lseq a blocksize). f i b_v == g i b_v) (ensures Lib.Sequence.map_blocks_multi blocksize max n inp f == Lib.Sequence.map_blocks_multi blocksize max n inp g)
{ "end_col": 5, "end_line": 629, "start_col": 64, "start_line": 612 }
FStar.Pervasives.Lemma
val repeat_blocks_multi_split: #a:Type0 -> #b:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq a{len0 <= length inp /\ length inp % blocksize = 0} -> f:(lseq a blocksize -> b -> b) -> acc0:b -> Lemma (let len = length inp in Math.Lemmas.lemma_div_exact len blocksize; split_len_lemma0 blocksize (len / blocksize) len0; Math.Lemmas.swap_mul blocksize (len / blocksize); repeat_blocks_multi blocksize inp f acc0 == repeat_blocks_multi blocksize (Seq.slice inp len0 len) f (repeat_blocks_multi blocksize (Seq.slice inp 0 len0) f acc0))
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; }
val repeat_blocks_multi_split: #a:Type0 -> #b:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq a{len0 <= length inp /\ length inp % blocksize = 0} -> f:(lseq a blocksize -> b -> b) -> acc0:b -> Lemma (let len = length inp in Math.Lemmas.lemma_div_exact len blocksize; split_len_lemma0 blocksize (len / blocksize) len0; Math.Lemmas.swap_mul blocksize (len / blocksize); repeat_blocks_multi blocksize inp f acc0 == repeat_blocks_multi blocksize (Seq.slice inp len0 len) f (repeat_blocks_multi blocksize (Seq.slice inp 0 len0) f acc0)) let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 =
false
null
true
let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc ( == ) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; ( == ) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; ( == ) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc ( == ) { repeat_blocks_multi blocksize inp f acc0; ( == ) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; ( == ) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; ( == ) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; ( == ) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Lib.Sequence.seq", "Prims.l_and", "Prims.op_LessThanOrEqual", "Lib.Sequence.length", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.Sequence.repeat_blocks_multi", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "Lib.LoopCombinators.fixed_a", "Lib.LoopCombinators.fixed_i", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.repeat_blocks_multi_is_repeat_gen_blocks_multi", "Prims.squash", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi_split", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi_extensionality_zero", "Prims.op_Addition", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.Sequence.Lemmas.split_len_lemma0", "Lib.Sequence.Lemmas.len0_le_len_fraction", "Prims.op_Division", "Prims.op_Subtraction" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_blocks_multi_split: #a:Type0 -> #b:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq a{len0 <= length inp /\ length inp % blocksize = 0} -> f:(lseq a blocksize -> b -> b) -> acc0:b -> Lemma (let len = length inp in Math.Lemmas.lemma_div_exact len blocksize; split_len_lemma0 blocksize (len / blocksize) len0; Math.Lemmas.swap_mul blocksize (len / blocksize); repeat_blocks_multi blocksize inp f acc0 == repeat_blocks_multi blocksize (Seq.slice inp len0 len) f (repeat_blocks_multi blocksize (Seq.slice inp 0 len0) f acc0))
[]
Lib.Sequence.Lemmas.repeat_blocks_multi_split
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize = 0} -> inp: Lib.Sequence.seq a {len0 <= Lib.Sequence.length inp /\ Lib.Sequence.length inp % blocksize = 0} -> f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> acc0: b -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in [@@ FStar.Pervasives.inline_let ]let _ = FStar.Math.Lemmas.lemma_div_exact len blocksize in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma0 blocksize (len / blocksize) len0 in [@@ FStar.Pervasives.inline_let ]let _ = FStar.Math.Lemmas.swap_mul blocksize (len / blocksize) in Lib.Sequence.repeat_blocks_multi blocksize inp f acc0 == Lib.Sequence.repeat_blocks_multi blocksize (FStar.Seq.Base.slice inp len0 len) f (Lib.Sequence.repeat_blocks_multi blocksize (FStar.Seq.Base.slice inp 0 len0) f acc0)))
{ "end_col": 5, "end_line": 551, "start_col": 63, "start_line": 518 }
FStar.Pervasives.Lemma
val repeat_blocks_split: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq a{len0 <= length inp} -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (let len = length inp in split_len_lemma blocksize len len0; repeat_blocks blocksize inp f l acc0 == repeat_blocks blocksize (Seq.slice inp len0 len) f l (repeat_blocks_multi blocksize (Seq.slice inp 0 len0) f acc0))
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; }
val repeat_blocks_split: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq a{len0 <= length inp} -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (let len = length inp in split_len_lemma blocksize len len0; repeat_blocks blocksize inp f l acc0 == repeat_blocks blocksize (Seq.slice inp len0 len) f l (repeat_blocks_multi blocksize (Seq.slice inp 0 len0) f acc0)) let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 =
false
null
true
let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc ( == ) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; ( == ) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; ( == ) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc ( == ) { repeat_blocks blocksize inp f l acc0; ( == ) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; ( == ) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; ( == ) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; ( == ) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Lib.Sequence.seq", "Prims.op_LessThanOrEqual", "Lib.Sequence.length", "Lib.Sequence.lseq", "Prims.op_LessThan", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.Sequence.repeat_blocks", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.Sequence.Lemmas.repeat_gen_blocks", "Lib.LoopCombinators.fixed_a", "Lib.LoopCombinators.fixed_i", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.Sequence.Lemmas.repeat_blocks_is_repeat_gen_blocks", "Prims.squash", "Lib.Sequence.Lemmas.repeat_gen_blocks_split", "Lib.Sequence.Lemmas.repeat_gen_blocks_extensionality_zero", "Prims.op_Addition", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "Lib.Sequence.repeat_blocks_multi", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi_extensionality_zero", "Lib.Sequence.Lemmas.repeat_blocks_multi_is_repeat_gen_blocks_multi", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.Sequence.Lemmas.split_len_lemma", "Lib.Sequence.Lemmas.len0_le_len_fraction", "Prims.op_Division", "Prims.op_Subtraction" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; }
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_blocks_split: #a:Type0 -> #b:Type0 -> #c:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq a{len0 <= length inp} -> f:(lseq a blocksize -> b -> b) -> l:(len:nat{len < blocksize} -> s:lseq a len -> b -> c) -> acc0:b -> Lemma (let len = length inp in split_len_lemma blocksize len len0; repeat_blocks blocksize inp f l acc0 == repeat_blocks blocksize (Seq.slice inp len0 len) f l (repeat_blocks_multi blocksize (Seq.slice inp 0 len0) f acc0))
[]
Lib.Sequence.Lemmas.repeat_blocks_split
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize = 0} -> inp: Lib.Sequence.seq a {len0 <= Lib.Sequence.length inp} -> f: (_: Lib.Sequence.lseq a blocksize -> _: b -> b) -> l: (len: Prims.nat{len < blocksize} -> s: Lib.Sequence.lseq a len -> _: b -> c) -> acc0: b -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma blocksize len len0 in Lib.Sequence.repeat_blocks blocksize inp f l acc0 == Lib.Sequence.repeat_blocks blocksize (FStar.Seq.Base.slice inp len0 len) f l (Lib.Sequence.repeat_blocks_multi blocksize (FStar.Seq.Base.slice inp 0 len0) f acc0)))
{ "end_col": 5, "end_line": 589, "start_col": 62, "start_line": 554 }
FStar.Pervasives.Lemma
val repeat_gen_blocks_multi_split: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n inp a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc)
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; }
val repeat_gen_blocks_multi_split: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n inp a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 =
false
null
true
let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1:a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in calc ( == ) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; ( == ) { () } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; ( == ) { (Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0) } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc ( == ) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; ( == ) { () } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; ( == ) { (Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1) } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; ( == ) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; ( == ) { () } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.l_and", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "FStar.Calc.calc_finish", "Lib.Sequence.Lemmas.repeat_gen_blocks_multi", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Lib.LoopCombinators.repeat_right", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Lib.Sequence.Lemmas.repeat_right_extensionality", "FStar.Classical.forall_intro_2", "Prims.op_Division", "Lib.Sequence.Lemmas.repeat_gen_blocks_f", "Prims.op_Subtraction", "FStar.Seq.Base.slice", "Lib.Sequence.Lemmas.aux_repeat_bf_s1", "Lib.LoopCombinators.repeat_right_plus", "Lib.Sequence.Lemmas.aux_repeat_bf_s0", "FStar.Seq.Base.seq", "Lib.Sequence.Lemmas.split_len_lemma0" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc)
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val repeat_gen_blocks_multi_split: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n inp a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc)
[]
Lib.Sequence.Lemmas.repeat_gen_blocks_multi_split
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> len0: Prims.nat{len0 % blocksize == 0} -> mi: Prims.nat -> hi: Prims.nat -> n: Prims.nat{mi + n <= hi} -> inp: Lib.Sequence.seq inp_t {len0 <= Lib.Sequence.length inp /\ Lib.Sequence.length inp == n * blocksize} -> a: (i: Prims.nat{i <= hi} -> Type) -> f: (i: Prims.nat{i < hi} -> _: Lib.Sequence.lseq inp_t blocksize -> _: a i -> a (i + 1)) -> acc0: a mi -> FStar.Pervasives.Lemma (ensures (let len = Lib.Sequence.length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in [@@ FStar.Pervasives.inline_let ]let _ = Lib.Sequence.Lemmas.split_len_lemma0 blocksize n len0 in let t0 = FStar.Seq.Base.slice inp 0 len0 in let t1 = FStar.Seq.Base.slice inp len0 len in let acc = Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize mi hi n inp a f acc0 == Lib.Sequence.Lemmas.repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc))
{ "end_col": 3, "end_line": 307, "start_col": 78, "start_line": 270 }
FStar.Pervasives.Lemma
val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a)))
[ { "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": 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": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g n inp f acc0 = let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_sh = f_shift blocksize mi hi_f hi_g f in let f_map = map_blocks_f #a blocksize hi_g inp f_sh in let lp = Loops.repeat_right mi (mi + n) a_f f_gen acc0 in let rp = Loops.repeat_right 0 n a_g f_map (Seq.empty #a) in if n = 0 then begin Loops.eq_repeat_right mi (mi + n) a_f f_gen acc0; Loops.eq_repeat_right 0 n a_g f_map (Seq.empty #a); Seq.Base.append_empty_r acc0 end else begin let lp1 = Loops.repeat_right mi (mi + n - 1) a_f f_gen acc0 in let rp1 = Loops.repeat_right 0 (n - 1) a_g f_map (Seq.empty #a) in let block = Seq.slice inp ((n - 1) * blocksize) (n * blocksize) in Loops.unfold_repeat_right 0 n a_g f_map (Seq.empty #a) (n - 1); assert (rp == f_map (n - 1) rp1); assert (rp == Seq.append rp1 (f (mi + n - 1) block)); calc (==) { Loops.repeat_right mi (mi + n) a_f f_gen acc0; (==) { Loops.unfold_repeat_right mi (mi + n) a_f f_gen acc0 (mi + n - 1) } Seq.append lp1 (f (mi + n - 1) block); (==) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g (n - 1) inp f acc0 } Seq.append (Seq.append acc0 rp1) (f (mi + n - 1) block); (==) { Seq.Base.append_assoc acc0 rp1 (f (mi + n - 1) block) } Seq.append acc0 (Seq.append rp1 (f (mi + n - 1) block)); } end
val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a))) let rec map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g n inp f acc0 =
false
null
true
let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_sh = f_shift blocksize mi hi_f hi_g f in let f_map = map_blocks_f #a blocksize hi_g inp f_sh in let lp = Loops.repeat_right mi (mi + n) a_f f_gen acc0 in let rp = Loops.repeat_right 0 n a_g f_map (Seq.empty #a) in if n = 0 then (Loops.eq_repeat_right mi (mi + n) a_f f_gen acc0; Loops.eq_repeat_right 0 n a_g f_map (Seq.empty #a); Seq.Base.append_empty_r acc0) else let lp1 = Loops.repeat_right mi (mi + n - 1) a_f f_gen acc0 in let rp1 = Loops.repeat_right 0 (n - 1) a_g f_map (Seq.empty #a) in let block = Seq.slice inp ((n - 1) * blocksize) (n * blocksize) in Loops.unfold_repeat_right 0 n a_g f_map (Seq.empty #a) (n - 1); assert (rp == f_map (n - 1) rp1); assert (rp == Seq.append rp1 (f (mi + n - 1) block)); calc ( == ) { Loops.repeat_right mi (mi + n) a_f f_gen acc0; ( == ) { Loops.unfold_repeat_right mi (mi + n) a_f f_gen acc0 (mi + n - 1) } Seq.append lp1 (f (mi + n - 1) block); ( == ) { map_blocks_multi_acc_is_map_blocks_multi_ #a blocksize mi hi_f hi_g (n - 1) inp f acc0 } Seq.append (Seq.append acc0 rp1) (f (mi + n - 1) block); ( == ) { Seq.Base.append_assoc acc0 rp1 (f (mi + n - 1) block) } Seq.append acc0 (Seq.append rp1 (f (mi + n - 1) block)); }
{ "checked_file": "Lib.Sequence.Lemmas.fst.checked", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.Base.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": "Lib.Sequence.Lemmas.fst" }
[ "lemma" ]
[ "Lib.IntTypes.size_pos", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Sequence.seq", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.Sequence.map_blocks_a", "Prims.op_Equality", "FStar.Seq.Base.append_empty_r", "Prims.unit", "Lib.LoopCombinators.eq_repeat_right", "FStar.Seq.Base.empty", "Prims.bool", "FStar.Calc.calc_finish", "Lib.LoopCombinators.repeat_right", "FStar.Seq.Base.append", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.LoopCombinators.unfold_repeat_right", "Prims.squash", "Lib.Sequence.Lemmas.map_blocks_multi_acc_is_map_blocks_multi_", "FStar.Seq.Base.append_assoc", "Prims._assert", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "Lib.Sequence.map_blocks_f", "Lib.Sequence.Lemmas.f_shift", "Lib.Sequence.Lemmas.repeat_gen_blocks_f", "Lib.Sequence.Lemmas.repeat_gen_blocks_map_f" ]
[]
module Lib.Sequence.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence #set-options "--z3rlimit 30 --max_fuel 0 --max_ifuel 0 \ --using_facts_from '-* +Prims +FStar.Pervasives +FStar.Math.Lemmas +FStar.Seq \ +Lib.IntTypes +Lib.Sequence +Lib.Sequence.Lemmas +Lib.LoopCombinators'" let rec repeati_extensionality #a n f g acc0 = if n = 0 then begin Loops.eq_repeati0 n f acc0; Loops.eq_repeati0 n g acc0 end else begin Loops.unfold_repeati n f acc0 (n-1); Loops.unfold_repeati n g acc0 (n-1); repeati_extensionality #a (n-1) f g acc0 end let rec repeat_right_extensionality n lo a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right lo (lo + n) a_f f acc0; Loops.eq_repeat_right lo (lo + n) a_g g acc0 end else begin Loops.unfold_repeat_right lo (lo + n) a_f f acc0 (lo + n - 1); Loops.unfold_repeat_right lo (lo + n) a_g g acc0 (lo + n - 1); repeat_right_extensionality (n - 1) lo a_f a_g f g acc0 end let rec repeat_gen_right_extensionality n lo_g a_f a_g f g acc0 = if n = 0 then begin Loops.eq_repeat_right 0 n a_f f acc0; Loops.eq_repeat_right lo_g (lo_g+n) a_g g acc0 end else begin Loops.unfold_repeat_right 0 n a_f f acc0 (n-1); Loops.unfold_repeat_right lo_g (lo_g+n) a_g g acc0 (lo_g+n-1); repeat_gen_right_extensionality (n-1) lo_g a_f a_g f g acc0 end let repeati_right_extensionality #a n lo_g f g acc0 = repeat_gen_right_extensionality n lo_g (Loops.fixed_a a) (Loops.fixed_a a) f g acc0 let repeati_right_shift #a n f g acc0 = let acc1 = g 0 acc0 in repeati_right_extensionality n 1 f g acc1; // Got: // repeat_right 0 n (fun _ -> a) f acc1 == repeat_right 1 (n + 1) (fun _ -> a) g acc1 Loops.repeati_def n f acc1; // Got: // repeati n f acc1 == repeat_right 0 n (fun _ -> a) f acc1 Loops.repeat_right_plus 0 1 (n + 1) (Loops.fixed_a a) g acc0; // Got: // repeat_right 0 (n + 1) (fixed_a a) g acc0 == // repeat_right 1 (n + 1) (fixed_a a) g (repeat_right 0 1 (fixed_a a) g acc0) Loops.unfold_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0 0; Loops.eq_repeat_right 0 (n + 1) (Loops.fixed_a a) g acc0; Loops.repeati_def (n + 1) g acc0 let repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = Loops.repeat_right mi (mi + n) a (repeat_gen_blocks_f blocksize mi hi n inp a f) acc0 let lemma_repeat_gen_blocks_multi #inp_t blocksize mi hi n inp a f acc0 = () let repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = let len = length inp in let nb = len / blocksize in let rem = len % blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in let last = Seq.slice inp (nb * blocksize) len in Math.Lemmas.cancel_mul_div nb blocksize; let acc = repeat_gen_blocks_multi #inp_t blocksize mi hi nb blocks a f acc0 in l (mi + nb) rem last acc let lemma_repeat_gen_blocks #inp_t #c blocksize mi hi inp a f l acc0 = () let repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n inp a_f a_g f g acc0 = let f_rep = repeat_gen_blocks_f blocksize mi hi_f n inp a_f f in let g_rep = repeat_gen_blocks_f blocksize 0 hi_g n inp a_g g in repeat_gen_right_extensionality n mi a_g a_f g_rep f_rep acc0 let repeat_gen_blocks_extensionality_zero #inp_t #c blocksize mi hi_f hi_g n inp a_f a_g f l_f g l_g acc0 = let len = length inp in let rem = len % blocksize in Math.Lemmas.cancel_mul_div n blocksize; Math.Lemmas.cancel_mul_mod n blocksize; let blocks = Seq.slice inp 0 (n * blocksize) in let block_l = Seq.slice inp (n * blocksize) len in let acc_f = repeat_gen_blocks_multi blocksize mi hi_f n blocks a_f f acc0 in let acc_g = repeat_gen_blocks_multi blocksize 0 hi_g n blocks a_g g acc0 in calc (==) { repeat_gen_blocks blocksize mi hi_f inp a_f f l_f acc0; (==) { } l_f (mi + n) rem block_l acc_f; (==) { repeat_gen_blocks_multi_extensionality_zero #inp_t blocksize mi hi_f hi_g n blocks a_f a_g f g acc0 } l_f (mi + n) rem block_l acc_g; (==) { } l_g n rem block_l acc_g; (==) { } repeat_gen_blocks blocksize 0 hi_g inp a_g g l_g acc0; } let len0_div_bs blocksize len len0 = let k = len0 / blocksize in calc (==) { k + (len - len0) / blocksize; == { Math.Lemmas.lemma_div_exact len0 blocksize } k + (len - k * blocksize) / blocksize; == { Math.Lemmas.division_sub_lemma len blocksize k } k + len / blocksize - k; == { } len / blocksize; } let split_len_lemma0 blocksize n len0 = let len = n * blocksize in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in Math.Lemmas.cancel_mul_mod n blocksize; //assert (len % blocksize = 0); Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len1 % blocksize = 0); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); Math.Lemmas.lemma_div_exact len1 blocksize; //assert (n1 * blocksize = len1); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) let split_len_lemma blocksize len len0 = let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in let n = len / blocksize in Math.Lemmas.lemma_mod_sub_distr len len0 blocksize; //assert (len % blocksize = len1 % blocksize); Math.Lemmas.lemma_div_exact len0 blocksize; //assert (n0 * blocksize = len0); len0_div_bs blocksize len len0 //assert (n0 + n1 = n) //////////////////////// // Start of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val aux_repeat_bf_s0: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi <= i /\ i < mi + len0 / blocksize /\ i < hi} // i < hi is needed to type-check the definition -> acc:a i -> Lemma (let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s0 i acc == repeat_bf_t i acc) let aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let n0 = len0 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n0; Seq.slice_slice inp 0 len0 (i_b * blocksize) (i_b * blocksize + blocksize); assert (repeat_bf_s0 i acc == f i block acc) val aux_repeat_bf_s1: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> n:nat{mi + n <= hi} -> inp:seq inp_t{len0 <= length inp /\ length inp == n * blocksize} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> i:nat{mi + len0 / blocksize <= i /\ i < mi + n} -> acc:a i -> Lemma (let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in repeat_bf_s1 i acc == repeat_bf_t i acc) let aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f i acc = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t1 = Seq.slice inp len0 len in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let i_b = i - mi in Math.Lemmas.lemma_mult_le_right blocksize (i_b + 1) n; let block = Seq.slice inp (i_b * blocksize) (i_b * blocksize + blocksize) in assert (repeat_bf_t i acc == f i block acc); let i_b1 = i - mi - n0 in calc (<=) { i_b1 * blocksize + blocksize; (<=) { Math.Lemmas.lemma_mult_le_right blocksize (i_b1 + 1) n1 } n1 * blocksize; (==) { Math.Lemmas.div_exact_r len1 blocksize } len1; }; calc (==) { len0 + i_b1 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n0 * blocksize + i_b1 * blocksize; (==) { Math.Lemmas.distributivity_add_left n0 i_b1 blocksize } (n0 + i_b1) * blocksize; }; Seq.slice_slice inp len0 len (i_b1 * blocksize) (i_b1 * blocksize + blocksize); assert (repeat_bf_s1 i acc == f i block acc) let repeat_gen_blocks_multi_split #inp_t blocksize len0 mi hi n inp a f acc0 = let len = length inp in let len1 = len - len0 in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let repeat_bf_s0 = repeat_gen_blocks_f blocksize mi hi n0 t0 a f in let repeat_bf_s1 = repeat_gen_blocks_f blocksize (mi + n0) hi n1 t1 a f in let repeat_bf_t = repeat_gen_blocks_f blocksize mi hi n inp a f in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in //let acc2 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1 in calc (==) { repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0; (==) { } Loops.repeat_right mi (mi + n0) a repeat_bf_s0 acc0; (==) { Classical.forall_intro_2 (aux_repeat_bf_s0 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n0 mi a a repeat_bf_s0 repeat_bf_t acc0 } Loops.repeat_right mi (mi + n0) a repeat_bf_t acc0; }; calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1; (==) { } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_s1 acc1; (==) { Classical.forall_intro_2 (aux_repeat_bf_s1 #inp_t blocksize len0 mi hi n inp a f); repeat_right_extensionality n1 (mi + n0) a a repeat_bf_s1 repeat_bf_t acc1 } Loops.repeat_right (mi + n0) (mi + n) a repeat_bf_t acc1; (==) { Loops.repeat_right_plus mi (mi + n0) (mi + n) a repeat_bf_t acc0 } Loops.repeat_right mi (mi + n) a repeat_bf_t acc0; (==) { } repeat_gen_blocks_multi blocksize mi hi n inp a f acc0; } //////////////////////// // End of proof of repeat_gen_blocks_multi_split lemma //////////////////////// val repeat_gen_blocks_multi_split_slice: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize == 0} -> mi:nat -> hi:nat -> inp:seq inp_t{len0 <= length inp / blocksize * blocksize /\ mi + length inp / blocksize <= hi} -> a:(i:nat{i <= hi} -> Type) -> f:(i:nat{i < hi} -> lseq inp_t blocksize -> a i -> a (i + 1)) -> acc0:a mi -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let blocks = Seq.slice inp 0 (n * blocksize) in let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 (n * blocksize) in let acc1 : a (mi + n0) = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in repeat_gen_blocks_multi blocksize mi hi n blocks a f acc0 == repeat_gen_blocks_multi blocksize (mi + n0) hi n1 t1 a f acc1) let repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 = let len = length inp in let n = len / blocksize in split_len_lemma blocksize len len0; let blocks = Seq.slice inp 0 (n * blocksize) in split_len_lemma0 blocksize n len0; repeat_gen_blocks_multi_split blocksize len0 mi hi n blocks a f acc0 val slice_slice_last: #inp_t:Type0 -> blocksize:size_pos -> len0:nat{len0 % blocksize = 0} -> inp:seq inp_t{len0 <= length inp} -> Lemma (let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n1 = len1 / blocksize in let t1 = Seq.slice inp len0 len in Seq.slice t1 (n1 * blocksize) len1 `Seq.equal` Seq.slice inp (n * blocksize) len) let slice_slice_last #inp_t blocksize len0 inp = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in calc (==) { len0 + n1 * blocksize; (==) { len0_div_bs blocksize len len0 } len0 + (n - n0) * blocksize; (==) { Math.Lemmas.distributivity_sub_left n n0 blocksize } len0 + n * blocksize - n0 * blocksize; (==) { Math.Lemmas.div_exact_r len0 blocksize } n * blocksize; }; let t1 = Seq.slice inp len0 len in Seq.slice_slice inp len0 len (n1 * blocksize) len1 val len0_le_len_fraction: blocksize:pos -> len:nat -> len0:nat -> Lemma (requires len0 <= len /\ len0 % blocksize = 0) (ensures len0 <= len / blocksize * blocksize) let len0_le_len_fraction blocksize len len0 = Math.Lemmas.lemma_div_le len0 len blocksize; Math.Lemmas.lemma_mult_le_right blocksize (len0 / blocksize) (len / blocksize) #push-options "--z3rlimit 100" let repeat_gen_blocks_split #inp_t #c blocksize len0 hi mi inp a f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc = repeat_gen_blocks_multi blocksize mi hi n0 t0 a f acc0 in let blocks1 = Seq.slice t1 0 (n1 * blocksize) in Math.Lemmas.cancel_mul_mod n1 blocksize; let acc1 = repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc in calc (==) { repeat_gen_blocks_multi blocksize (mi + n0) hi n1 blocks1 a f acc; (==) { repeat_gen_blocks_multi_split_slice #inp_t blocksize len0 mi hi inp a f acc0 } repeat_gen_blocks_multi blocksize mi hi n (Seq.slice inp 0 (n * blocksize)) a f acc0; }; calc (==) { repeat_gen_blocks blocksize (mi + n0) hi t1 a f l acc; (==) { len0_div_bs blocksize len len0 } l (mi + n) (len1 % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { Math.Lemmas.lemma_mod_sub_distr len len0 blocksize } l (mi + n) (len % blocksize) (Seq.slice t1 (n1 * blocksize) len1) acc1; (==) { slice_slice_last #inp_t blocksize len0 inp } l (mi + n) (len % blocksize) (Seq.slice inp (n * blocksize) len) acc1; } #pop-options //////////////////////// // Start of repeat_blocks-related properties //////////////////////// let repeat_blocks_extensionality #a #b #c blocksize inp f1 f2 l1 l2 acc0 = let len = length inp in let nb = len / blocksize in let f_rep1 = repeat_blocks_f blocksize inp f1 nb in let f_rep2 = repeat_blocks_f blocksize inp f2 nb in let acc1 = Loops.repeati nb f_rep1 acc0 in let acc2 = Loops.repeati nb f_rep2 acc0 in lemma_repeat_blocks blocksize inp f1 l1 acc0; lemma_repeat_blocks blocksize inp f2 l2 acc0; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep1 i acc == f_rep2 i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep1 f_rep2 acc0 let lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in let blocks = Seq.slice inp 0 (nb * blocksize) in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let f_rep_b = repeat_blocks_f blocksize blocks f nb in let f_rep = repeat_blocks_f blocksize inp f nb in let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep_b i acc == f_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in lemma_repeat_blocks #a #b #c blocksize inp f l acc0; calc (==) { Loops.repeati nb f_rep acc0; (==) { Classical.forall_intro_2 aux; repeati_extensionality nb f_rep f_rep_b acc0 } Loops.repeati nb f_rep_b acc0; (==) { lemma_repeat_blocks_multi blocksize blocks f acc0 } repeat_blocks_multi blocksize blocks f acc0; } let repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize inp f acc0 = let len = length inp in let n = len / blocksize in Math.Lemmas.div_exact_r len blocksize; let f_rep = repeat_blocks_f blocksize inp f n in let f_gen = repeat_gen_blocks_f blocksize 0 hi n inp (Loops.fixed_a b) (Loops.fixed_i f) in let aux (i:nat{i < n}) (acc:b) : Lemma (f_rep i acc == f_gen i acc) = () in calc (==) { repeat_blocks_multi #a #b blocksize inp f acc0; (==) { lemma_repeat_blocks_multi #a #b blocksize inp f acc0 } Loops.repeati n f_rep acc0; (==) { Loops.repeati_def n (repeat_blocks_f blocksize inp f n) acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_rep acc0; (==) { Classical.forall_intro_2 aux; repeat_gen_right_extensionality n 0 (Loops.fixed_a b) (Loops.fixed_a b) f_rep f_gen acc0 } Loops.repeat_right 0 n (Loops.fixed_a b) f_gen acc0; } let repeat_blocks_is_repeat_gen_blocks #a #b #c hi blocksize inp f l acc0 = let len = length inp in let nb = len / blocksize in //let rem = len % blocksize in Math.Lemmas.cancel_mul_div nb blocksize; Math.Lemmas.cancel_mul_mod nb blocksize; let blocks = Seq.slice inp 0 (nb * blocksize) in lemma_repeat_blocks_via_multi #a #b #c blocksize inp f l acc0; calc (==) { repeat_blocks_multi blocksize blocks f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b hi blocksize blocks f acc0 } repeat_gen_blocks_multi blocksize 0 hi nb blocks (Loops.fixed_a b) (Loops.fixed_i f) acc0; } let repeat_blocks_multi_split #a #b blocksize len0 inp f acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma0 blocksize n len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks_multi blocksize inp f acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n blocksize inp f acc0 } repeat_gen_blocks_multi blocksize 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_split #a blocksize len0 0 n n inp (Loops.fixed_a b) (Loops.fixed_i f) acc0 } repeat_gen_blocks_multi blocksize n0 n n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc1 } repeat_gen_blocks_multi blocksize 0 n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) acc1; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n1 blocksize t1 f acc1 } repeat_blocks_multi blocksize t1 f acc1; } let repeat_blocks_split #a #b #c blocksize len0 inp f l acc0 = let len = length inp in let len1 = len - len0 in let n = len / blocksize in let n0 = len0 / blocksize in let n1 = len1 / blocksize in len0_le_len_fraction blocksize len len0; split_len_lemma blocksize len len0; let t0 = Seq.slice inp 0 len0 in let t1 = Seq.slice inp len0 len in let acc1 = repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0 in calc (==) { repeat_gen_blocks_multi blocksize 0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_gen_blocks_multi_extensionality_zero blocksize 0 n0 n n0 t0 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i f) acc0} repeat_gen_blocks_multi blocksize 0 n0 n0 t0 (Loops.fixed_a b) (Loops.fixed_i f) acc0; (==) { repeat_blocks_multi_is_repeat_gen_blocks_multi #a #b n0 blocksize t0 f acc0 } repeat_blocks_multi blocksize t0 f acc0; }; calc (==) { repeat_blocks blocksize inp f l acc0; (==) { repeat_blocks_is_repeat_gen_blocks n blocksize inp f l acc0 } repeat_gen_blocks blocksize 0 n inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0; (==) { repeat_gen_blocks_split #a #c blocksize len0 n 0 inp (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc0 } repeat_gen_blocks blocksize n0 n t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_gen_blocks_extensionality_zero blocksize n0 n n1 n1 t1 (Loops.fixed_a b) (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) (Loops.fixed_i f) (Loops.fixed_i l) acc1 } repeat_gen_blocks blocksize 0 n1 t1 (Loops.fixed_a b) (Loops.fixed_i f) (Loops.fixed_i l) acc1; (==) { repeat_blocks_is_repeat_gen_blocks #a #b #c n1 blocksize t1 f l acc1 } repeat_blocks blocksize t1 f l acc1; } let repeat_blocks_multi_extensionality #a #b blocksize inp f g init = let len = length inp in let nb = len / blocksize in let f_rep = repeat_blocks_f blocksize inp f nb in let g_rep = repeat_blocks_f blocksize inp g nb in lemma_repeat_blocks_multi blocksize inp f init; lemma_repeat_blocks_multi blocksize inp g init; let aux (i:nat{i < nb}) (acc:b) : Lemma (f_rep i acc == g_rep i acc) = Math.Lemmas.lemma_mult_le_right blocksize (i + 1) nb; Seq.Properties.slice_slice inp 0 (nb * blocksize) (i * blocksize) (i * blocksize + blocksize) in Classical.forall_intro_2 aux; repeati_extensionality nb f_rep g_rep init //////////////////////// // End of repeat_blocks-related properties //////////////////////// let map_blocks_multi_extensionality #a blocksize max n inp f g = let a_map = map_blocks_a a blocksize max in let acc0 : a_map 0 = Seq.empty #a in calc (==) { map_blocks_multi blocksize max n inp f; (==) { lemma_map_blocks_multi blocksize max n inp f } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp f) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp f) acc0; (==) { repeat_right_extensionality n 0 a_map a_map (map_blocks_f #a blocksize max inp f) (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_right 0 n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { Loops.repeat_gen_def n a_map (map_blocks_f #a blocksize max inp g) acc0 } Loops.repeat_gen n a_map (map_blocks_f #a blocksize max inp g) acc0; (==) { lemma_map_blocks_multi blocksize max n inp g } map_blocks_multi blocksize max n inp g; } let map_blocks_extensionality #a blocksize inp f l_f g l_g = let len = length inp in let n = len / blocksize in let blocks = Seq.slice inp 0 (n * blocksize) in lemma_map_blocks blocksize inp f l_f; lemma_map_blocks blocksize inp g l_g; map_blocks_multi_extensionality #a blocksize n n blocks f g let repeat_gen_blocks_map_l_length #a blocksize hi l i rem block_l acc = () let map_blocks_multi_acc #a blocksize mi hi n inp f acc0 = repeat_gen_blocks_multi #a blocksize mi hi n inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) acc0 let map_blocks_acc #a blocksize mi hi inp f l acc0 = repeat_gen_blocks #a blocksize mi hi inp (map_blocks_a a blocksize hi) (repeat_gen_blocks_map_f blocksize hi f) (repeat_gen_blocks_map_l blocksize hi l) acc0 let map_blocks_acc_length #a blocksize mi hi inp f l acc0 = () let map_blocks_multi_acc_is_repeat_gen_blocks_multi #a blocksize mi hi n inp f acc0 = () let map_blocks_acc_is_repeat_gen_blocks #a blocksize mi hi inp f l acc0 = () #push-options "--z3rlimit 150" val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a)))
false
false
Lib.Sequence.Lemmas.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 150, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val map_blocks_multi_acc_is_map_blocks_multi_: #a:Type0 -> blocksize:size_pos -> mi:nat -> hi_f:nat -> hi_g:nat -> n:nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp:seq a{length inp == hi_g * blocksize} -> f:(i:nat{i < hi_f} -> lseq a blocksize -> lseq a blocksize) -> acc0:map_blocks_a a blocksize hi_f mi -> Lemma (let a_f = map_blocks_a a blocksize hi_f in let a_g = map_blocks_a a blocksize hi_g in let f_gen_map = repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = map_blocks_f #a blocksize hi_g inp (f_shift blocksize mi hi_f hi_g f) in Loops.repeat_right mi (mi + n) a_f f_gen acc0 == Seq.append acc0 (Loops.repeat_right 0 n a_g f_map (Seq.empty #a)))
[ "recursion" ]
Lib.Sequence.Lemmas.map_blocks_multi_acc_is_map_blocks_multi_
{ "file_name": "lib/Lib.Sequence.Lemmas.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
blocksize: Lib.IntTypes.size_pos -> mi: Prims.nat -> hi_f: Prims.nat -> hi_g: Prims.nat -> n: Prims.nat{mi + hi_g <= hi_f /\ n <= hi_g} -> inp: Lib.Sequence.seq a {Lib.Sequence.length inp == hi_g * blocksize} -> f: (i: Prims.nat{i < hi_f} -> _: Lib.Sequence.lseq a blocksize -> Lib.Sequence.lseq a blocksize) -> acc0: Lib.Sequence.map_blocks_a a blocksize hi_f mi -> FStar.Pervasives.Lemma (ensures (let a_f = Lib.Sequence.map_blocks_a a blocksize hi_f in let a_g = Lib.Sequence.map_blocks_a a blocksize hi_g in let f_gen_map = Lib.Sequence.Lemmas.repeat_gen_blocks_map_f blocksize hi_f f in let f_gen = Lib.Sequence.Lemmas.repeat_gen_blocks_f blocksize mi hi_f hi_g inp a_f f_gen_map in let f_map = Lib.Sequence.map_blocks_f blocksize hi_g inp (Lib.Sequence.Lemmas.f_shift blocksize mi hi_f hi_g f) in Lib.LoopCombinators.repeat_right mi (mi + n) a_f f_gen acc0 == FStar.Seq.Base.append acc0 (Lib.LoopCombinators.repeat_right 0 n a_g f_map FStar.Seq.Base.empty)))
{ "end_col": 11, "end_line": 716, "start_col": 90, "start_line": 685 }
Prims.GTot
val serialize32_bounded_vlgen_precond (min: nat) (max: nat{min <= max}) (sk k: parser_kind) : GTot bool
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize32_bounded_vlgen_precond (min: nat) (max: nat { min <= max } ) (sk: parser_kind) (k: parser_kind) : GTot bool = match sk.parser_kind_high with | None -> false | Some kmax -> let max' = match k.parser_kind_high with | None -> max | Some km -> if km < max then km else max in kmax + max' < 4294967296
val serialize32_bounded_vlgen_precond (min: nat) (max: nat{min <= max}) (sk k: parser_kind) : GTot bool let serialize32_bounded_vlgen_precond (min: nat) (max: nat{min <= max}) (sk k: parser_kind) : GTot bool =
false
null
false
match sk.parser_kind_high with | None -> false | Some kmax -> let max' = match k.parser_kind_high with | None -> max | Some km -> if km < max then km else max in kmax + max' < 4294967296
{ "checked_file": "LowParse.SLow.VLGen.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLGen.fst.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLGen.fst" }
[ "sometrivial" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "Prims.op_LessThan", "Prims.op_Addition", "Prims.int", "Prims.bool" ]
[]
module LowParse.SLow.VLGen include LowParse.SLow.Combinators include LowParse.SLow.FLData include LowParse.Spec.VLGen module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 inline_for_extraction let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) = fun (input: bytes32) -> (( [@inline_let] let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed') ) <: (res: _ { parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res } )) inline_for_extraction let parse32_vlgen (vmin: nat) (min: U32.t { U32.v min == vmin } ) (vmax: nat) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k } ) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) = parse32_synth' _ (synth_vlgen (U32.v min) (U32.v max) s) (parse32_bounded_vlgen vmin min vmax max pk32 s p32) () let serialize32_bounded_vlgen_precond (min: nat) (max: nat { min <= max } ) (sk: parser_kind) (k: parser_kind)
false
false
LowParse.SLow.VLGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize32_bounded_vlgen_precond (min: nat) (max: nat{min <= max}) (sk k: parser_kind) : GTot bool
[]
LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond
{ "file_name": "src/lowparse/LowParse.SLow.VLGen.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max} -> sk: LowParse.Spec.Base.parser_kind -> k: LowParse.Spec.Base.parser_kind -> Prims.GTot Prims.bool
{ "end_col": 28, "end_line": 70, "start_col": 2, "start_line": 63 }
Prims.Tot
val serialize32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_vlgen min max ssk s))
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize32_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k } ) : Tot (serializer32 (serialize_vlgen min max ssk s)) = serialize32_synth' _ (synth_vlgen min max s) _ (serialize32_bounded_vlgen min max ssk32 s32) (synth_vlgen_recip min max s) ()
val serialize32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_vlgen min max ssk s)) let serialize32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_vlgen min max ssk s)) =
false
null
false
serialize32_synth' _ (synth_vlgen min max s) _ (serialize32_bounded_vlgen min max ssk32 s32) (synth_vlgen_recip min max s) ()
{ "checked_file": "LowParse.SLow.VLGen.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLGen.fst.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLGen.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.serializer32", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.SLow.Base.partial_serializer32", "LowParse.Spec.VLGen.parse_vlgen_precond", "LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond", "LowParse.SLow.Combinators.serialize32_synth'", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Spec.VLGen.synth_vlgen", "LowParse.Spec.VLGen.serialize_bounded_vlgen", "LowParse.SLow.VLGen.serialize32_bounded_vlgen", "LowParse.Spec.VLGen.synth_vlgen_recip", "LowParse.Spec.VLGen.parse_vlgen", "LowParse.Spec.VLGen.serialize_vlgen" ]
[]
module LowParse.SLow.VLGen include LowParse.SLow.Combinators include LowParse.SLow.FLData include LowParse.Spec.VLGen module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 inline_for_extraction let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) = fun (input: bytes32) -> (( [@inline_let] let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed') ) <: (res: _ { parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res } )) inline_for_extraction let parse32_vlgen (vmin: nat) (min: U32.t { U32.v min == vmin } ) (vmax: nat) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k } ) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) = parse32_synth' _ (synth_vlgen (U32.v min) (U32.v max) s) (parse32_bounded_vlgen vmin min vmax max pk32 s p32) () let serialize32_bounded_vlgen_precond (min: nat) (max: nat { min <= max } ) (sk: parser_kind) (k: parser_kind) : GTot bool = match sk.parser_kind_high with | None -> false | Some kmax -> let max' = match k.parser_kind_high with | None -> max | Some km -> if km < max then km else max in kmax + max' < 4294967296 inline_for_extraction let serialize32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize32_bounded_vlgen_precond min max sk k } ) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> (( [@inline_let] let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in let len = B32.len sp in ssk32 len `B32.append` sp ) <: (res: _ { serializer32_correct (serialize_bounded_vlgen min max ssk s) input res } )) inline_for_extraction let serialize32_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k } )
false
false
LowParse.SLow.VLGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_vlgen min max ssk s))
[]
LowParse.SLow.VLGen.serialize32_vlgen
{ "file_name": "src/lowparse/LowParse.SLow.VLGen.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max < 4294967296} -> ssk32: LowParse.SLow.Base.serializer32 ssk { Mkparser_kind'?.parser_kind_subkind sk == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> s32: LowParse.SLow.Base.partial_serializer32 s { LowParse.Spec.VLGen.parse_vlgen_precond min max k /\ LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond min max sk k } -> LowParse.SLow.Base.serializer32 (LowParse.Spec.VLGen.serialize_vlgen min max ssk s)
{ "end_col": 6, "end_line": 114, "start_col": 2, "start_line": 108 }
Prims.Tot
val size32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k} ) : Tot (size32 (serialize_vlgen min max ssk s))
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let size32_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s { parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k } ) : Tot (size32 (serialize_vlgen min max ssk s)) = size32_synth' _ (synth_vlgen min max s) _ (size32_bounded_vlgen min max ssk32 s32) (synth_vlgen_recip min max s) ()
val size32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k} ) : Tot (size32 (serialize_vlgen min max ssk s)) let size32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k} ) : Tot (size32 (serialize_vlgen min max ssk s)) =
false
null
false
size32_synth' _ (synth_vlgen min max s) _ (size32_bounded_vlgen min max ssk32 s32) (synth_vlgen_recip min max s) ()
{ "checked_file": "LowParse.SLow.VLGen.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLGen.fst.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLGen.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Spec.VLGen.parse_vlgen_precond", "LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond", "LowParse.SLow.Combinators.size32_synth'", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Spec.VLGen.synth_vlgen", "LowParse.Spec.VLGen.serialize_bounded_vlgen", "LowParse.SLow.VLGen.size32_bounded_vlgen", "LowParse.Spec.VLGen.synth_vlgen_recip", "LowParse.Spec.VLGen.parse_vlgen", "LowParse.Spec.VLGen.serialize_vlgen" ]
[]
module LowParse.SLow.VLGen include LowParse.SLow.Combinators include LowParse.SLow.FLData include LowParse.Spec.VLGen module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 inline_for_extraction let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) = fun (input: bytes32) -> (( [@inline_let] let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed') ) <: (res: _ { parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res } )) inline_for_extraction let parse32_vlgen (vmin: nat) (min: U32.t { U32.v min == vmin } ) (vmax: nat) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k } ) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) = parse32_synth' _ (synth_vlgen (U32.v min) (U32.v max) s) (parse32_bounded_vlgen vmin min vmax max pk32 s p32) () let serialize32_bounded_vlgen_precond (min: nat) (max: nat { min <= max } ) (sk: parser_kind) (k: parser_kind) : GTot bool = match sk.parser_kind_high with | None -> false | Some kmax -> let max' = match k.parser_kind_high with | None -> max | Some km -> if km < max then km else max in kmax + max' < 4294967296 inline_for_extraction let serialize32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize32_bounded_vlgen_precond min max sk k } ) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> (( [@inline_let] let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in let len = B32.len sp in ssk32 len `B32.append` sp ) <: (res: _ { serializer32_correct (serialize_bounded_vlgen min max ssk s) input res } )) inline_for_extraction let serialize32_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k } ) : Tot (serializer32 (serialize_vlgen min max ssk s)) = serialize32_synth' _ (synth_vlgen min max s) _ (serialize32_bounded_vlgen min max ssk32 s32) (synth_vlgen_recip min max s) () inline_for_extraction let size32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s { serialize32_bounded_vlgen_precond min max sk k } ) : Tot (size32 (serialize_bounded_vlgen min max ssk s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> (( [@inline_let] let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in ssk32 sp `U32.add` sp ) <: (res: _ { size32_postcond (serialize_bounded_vlgen min max ssk s) input res } )) inline_for_extraction let size32_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s { parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k } )
false
false
LowParse.SLow.VLGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val size32_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k} ) : Tot (size32 (serialize_vlgen min max ssk s))
[]
LowParse.SLow.VLGen.size32_vlgen
{ "file_name": "src/lowparse/LowParse.SLow.VLGen.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max < 4294967296} -> ssk32: LowParse.SLow.Base.size32 ssk { Mkparser_kind'?.parser_kind_subkind sk == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> s32: LowParse.SLow.Base.size32 s { LowParse.Spec.VLGen.parse_vlgen_precond min max k /\ LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond min max sk k } -> LowParse.SLow.Base.size32 (LowParse.Spec.VLGen.serialize_vlgen min max ssk s)
{ "end_col": 6, "end_line": 157, "start_col": 2, "start_line": 151 }
Prims.Tot
val serialize32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s))
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize32_bounded_vlgen_precond min max sk k } ) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> (( [@inline_let] let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in let len = B32.len sp in ssk32 len `B32.append` sp ) <: (res: _ { serializer32_correct (serialize_bounded_vlgen min max ssk s) input res } ))
val serialize32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s)) let serialize32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s)) =
false
null
false
fun (input: parse_bounded_vldata_strong_t min max s) -> (([@@ inline_let ]let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in let len = B32.len sp in (ssk32 len) `B32.append` sp) <: (res: _{serializer32_correct (serialize_bounded_vlgen min max ssk s) input res}))
{ "checked_file": "LowParse.SLow.VLGen.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLGen.fst.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLGen.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.serializer32", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.SLow.Base.partial_serializer32", "LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.append", "FStar.UInt32.t", "FStar.Bytes.len", "LowParse.SLow.Base.bytes32", "LowParse.SLow.Base.serializer32_correct", "Prims.unit", "LowParse.Spec.VLGen.serialize_bounded_vlgen_unfold", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Spec.VLGen.serialize_bounded_vlgen" ]
[]
module LowParse.SLow.VLGen include LowParse.SLow.Combinators include LowParse.SLow.FLData include LowParse.Spec.VLGen module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 inline_for_extraction let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) = fun (input: bytes32) -> (( [@inline_let] let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed') ) <: (res: _ { parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res } )) inline_for_extraction let parse32_vlgen (vmin: nat) (min: U32.t { U32.v min == vmin } ) (vmax: nat) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k } ) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) = parse32_synth' _ (synth_vlgen (U32.v min) (U32.v max) s) (parse32_bounded_vlgen vmin min vmax max pk32 s p32) () let serialize32_bounded_vlgen_precond (min: nat) (max: nat { min <= max } ) (sk: parser_kind) (k: parser_kind) : GTot bool = match sk.parser_kind_high with | None -> false | Some kmax -> let max' = match k.parser_kind_high with | None -> max | Some km -> if km < max then km else max in kmax + max' < 4294967296 inline_for_extraction let serialize32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize32_bounded_vlgen_precond min max sk k } )
false
false
LowParse.SLow.VLGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s))
[]
LowParse.SLow.VLGen.serialize32_bounded_vlgen
{ "file_name": "src/lowparse/LowParse.SLow.VLGen.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max < 4294967296} -> ssk32: LowParse.SLow.Base.serializer32 ssk { Mkparser_kind'?.parser_kind_subkind sk == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> s32: LowParse.SLow.Base.partial_serializer32 s {LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond min max sk k} -> LowParse.SLow.Base.serializer32 (LowParse.Spec.VLGen.serialize_bounded_vlgen min max ssk s)
{ "end_col": 92, "end_line": 92, "start_col": 2, "start_line": 86 }
Prims.Tot
val parse32_vlgen (vmin: nat) (min: U32.t{U32.v min == vmin}) (vmax: nat) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p {parse_vlgen_precond (U32.v min) (U32.v max) k}) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s))
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse32_vlgen (vmin: nat) (min: U32.t { U32.v min == vmin } ) (vmax: nat) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k } ) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) = parse32_synth' _ (synth_vlgen (U32.v min) (U32.v max) s) (parse32_bounded_vlgen vmin min vmax max pk32 s p32) ()
val parse32_vlgen (vmin: nat) (min: U32.t{U32.v min == vmin}) (vmax: nat) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p {parse_vlgen_precond (U32.v min) (U32.v max) k}) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) let parse32_vlgen (vmin: nat) (min: U32.t{U32.v min == vmin}) (vmax: nat) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p {parse_vlgen_precond (U32.v min) (U32.v max) k}) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) =
false
null
false
parse32_synth' _ (synth_vlgen (U32.v min) (U32.v max) s) (parse32_bounded_vlgen vmin min vmax max pk32 s p32) ()
{ "checked_file": "LowParse.SLow.VLGen.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLGen.fst.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLGen.fst" }
[ "total" ]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.SLow.Base.parser32", "LowParse.Spec.Base.serializer", "LowParse.Spec.VLGen.parse_vlgen_precond", "LowParse.SLow.Combinators.parse32_synth'", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Spec.VLGen.synth_vlgen", "LowParse.SLow.VLGen.parse32_bounded_vlgen", "LowParse.Spec.VLGen.parse_vlgen" ]
[]
module LowParse.SLow.VLGen include LowParse.SLow.Combinators include LowParse.SLow.FLData include LowParse.Spec.VLGen module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 inline_for_extraction let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) = fun (input: bytes32) -> (( [@inline_let] let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed') ) <: (res: _ { parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res } )) inline_for_extraction let parse32_vlgen (vmin: nat) (min: U32.t { U32.v min == vmin } ) (vmax: nat) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k } ) (p32: parser32 p)
false
false
LowParse.SLow.VLGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse32_vlgen (vmin: nat) (min: U32.t{U32.v min == vmin}) (vmax: nat) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p {parse_vlgen_precond (U32.v min) (U32.v max) k}) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s))
[]
LowParse.SLow.VLGen.parse32_vlgen
{ "file_name": "src/lowparse/LowParse.SLow.VLGen.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
vmin: Prims.nat -> min: FStar.UInt32.t{FStar.UInt32.v min == vmin} -> vmax: Prims.nat -> max: FStar.UInt32.t{FStar.UInt32.v max == vmax /\ FStar.UInt32.v min <= FStar.UInt32.v max} -> pk32: LowParse.SLow.Base.parser32 pk -> s: LowParse.Spec.Base.serializer p {LowParse.Spec.VLGen.parse_vlgen_precond (FStar.UInt32.v min) (FStar.UInt32.v max) k} -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLGen.parse_vlgen vmin vmax pk s)
{ "end_col": 6, "end_line": 55, "start_col": 2, "start_line": 51 }
Prims.Tot
val size32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (size32 (serialize_bounded_vlgen min max ssk s))
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let size32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s { serialize32_bounded_vlgen_precond min max sk k } ) : Tot (size32 (serialize_bounded_vlgen min max ssk s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> (( [@inline_let] let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in ssk32 sp `U32.add` sp ) <: (res: _ { size32_postcond (serialize_bounded_vlgen min max ssk s) input res } ))
val size32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (size32 (serialize_bounded_vlgen min max ssk s)) let size32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (size32 (serialize_bounded_vlgen min max ssk s)) =
false
null
false
fun (input: parse_bounded_vldata_strong_t min max s) -> (([@@ inline_let ]let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in (ssk32 sp) `U32.add` sp) <: (res: _{size32_postcond (serialize_bounded_vlgen min max ssk s) input res}))
{ "checked_file": "LowParse.SLow.VLGen.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLGen.fst.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLGen.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.UInt32.add", "FStar.UInt32.t", "LowParse.SLow.Base.size32_postcond", "Prims.unit", "LowParse.Spec.VLGen.serialize_bounded_vlgen_unfold", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Spec.VLGen.serialize_bounded_vlgen" ]
[]
module LowParse.SLow.VLGen include LowParse.SLow.Combinators include LowParse.SLow.FLData include LowParse.Spec.VLGen module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 inline_for_extraction let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) = fun (input: bytes32) -> (( [@inline_let] let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed') ) <: (res: _ { parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res } )) inline_for_extraction let parse32_vlgen (vmin: nat) (min: U32.t { U32.v min == vmin } ) (vmax: nat) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p { parse_vlgen_precond (U32.v min) (U32.v max) k } ) (p32: parser32 p) : Tot (parser32 (parse_vlgen (vmin) (vmax) pk s)) = parse32_synth' _ (synth_vlgen (U32.v min) (U32.v max) s) (parse32_bounded_vlgen vmin min vmax max pk32 s p32) () let serialize32_bounded_vlgen_precond (min: nat) (max: nat { min <= max } ) (sk: parser_kind) (k: parser_kind) : GTot bool = match sk.parser_kind_high with | None -> false | Some kmax -> let max' = match k.parser_kind_high with | None -> max | Some km -> if km < max then km else max in kmax + max' < 4294967296 inline_for_extraction let serialize32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize32_bounded_vlgen_precond min max sk k } ) : Tot (serializer32 (serialize_bounded_vlgen min max ssk s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> (( [@inline_let] let _ = serialize_bounded_vlgen_unfold min max ssk s input in let sp = s32 input in let len = B32.len sp in ssk32 len `B32.append` sp ) <: (res: _ { serializer32_correct (serialize_bounded_vlgen min max ssk s) input res } )) inline_for_extraction let serialize32_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: serializer32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { parse_vlgen_precond min max k /\ serialize32_bounded_vlgen_precond min max sk k } ) : Tot (serializer32 (serialize_vlgen min max ssk s)) = serialize32_synth' _ (synth_vlgen min max s) _ (serialize32_bounded_vlgen min max ssk32 s32) (synth_vlgen_recip min max s) () inline_for_extraction let size32_bounded_vlgen (min: nat) (max: nat { min <= max /\ max < 4294967296 } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk { sk.parser_kind_subkind == Some ParserStrong } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s { serialize32_bounded_vlgen_precond min max sk k } )
false
false
LowParse.SLow.VLGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val size32_bounded_vlgen (min: nat) (max: nat{min <= max /\ max < 4294967296}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 min max)) (#ssk: serializer pk) (ssk32: size32 ssk {sk.parser_kind_subkind == Some ParserStrong}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {serialize32_bounded_vlgen_precond min max sk k}) : Tot (size32 (serialize_bounded_vlgen min max ssk s))
[]
LowParse.SLow.VLGen.size32_bounded_vlgen
{ "file_name": "src/lowparse/LowParse.SLow.VLGen.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max < 4294967296} -> ssk32: LowParse.SLow.Base.size32 ssk { Mkparser_kind'?.parser_kind_subkind sk == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> s32: LowParse.SLow.Base.size32 s {LowParse.SLow.VLGen.serialize32_bounded_vlgen_precond min max sk k} -> LowParse.SLow.Base.size32 (LowParse.Spec.VLGen.serialize_bounded_vlgen min max ssk s)
{ "end_col": 87, "end_line": 135, "start_col": 2, "start_line": 130 }
Prims.Tot
val parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s))
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Spec.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) = fun (input: bytes32) -> (( [@inline_let] let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed') ) <: (res: _ { parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res } ))
val parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s)) =
false
null
false
fun (input: bytes32) -> (([@@ inline_let ]let _ = parse_bounded_vlgen_unfold_aux (U32.v min) (U32.v max) pk s (B32.reveal input) in match pk32 input with | None -> None | Some (sz, consumed) -> let input' = B32.slice input consumed (B32.len input) in match parse32_fldata_strong s p32 (U32.v sz) sz input' with | None -> None | Some (x, consumed') -> Some ((x <: parse_bounded_vldata_strong_t (U32.v min) (U32.v max) s), consumed `U32.add` consumed')) <: (res: _{parser32_correct (parse_bounded_vlgen (U32.v min) (U32.v max) pk s) input res}))
{ "checked_file": "LowParse.SLow.VLGen.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLGen.fst.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLGen.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.UInt32.v", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.SLow.Base.parser32", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.bytes32", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.SLow.FLData.parse32_fldata_strong", "LowParse.Spec.FLData.parse_fldata_strong_t", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.add", "FStar.Pervasives.Native.option", "LowParse.SLow.Base.parser32_correct", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.VLGen.parse_bounded_vlgen", "FStar.Bytes.bytes", "FStar.Seq.Base.seq", "FStar.UInt8.t", "FStar.Bytes.reveal", "FStar.Seq.Base.slice", "FStar.Bytes.len", "FStar.Bytes.slice", "Prims.unit", "LowParse.Spec.VLGen.parse_bounded_vlgen_unfold_aux" ]
[]
module LowParse.SLow.VLGen include LowParse.SLow.Combinators include LowParse.SLow.FLData include LowParse.Spec.VLGen module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 inline_for_extraction let parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p)
false
false
LowParse.SLow.VLGen.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse32_bounded_vlgen (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#sk: parser_kind) (#pk: parser sk (bounded_int32 (U32.v min) (U32.v max))) (pk32: parser32 pk) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 (parse_bounded_vlgen (vmin) (vmax) pk s))
[]
LowParse.SLow.VLGen.parse32_bounded_vlgen
{ "file_name": "src/lowparse/LowParse.SLow.VLGen.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
vmin: LowParse.Spec.DER.der_length_t -> min: FStar.UInt32.t{FStar.UInt32.v min == vmin} -> vmax: LowParse.Spec.DER.der_length_t -> max: FStar.UInt32.t{FStar.UInt32.v max == vmax /\ FStar.UInt32.v min <= FStar.UInt32.v max} -> pk32: LowParse.SLow.Base.parser32 pk -> s: LowParse.Spec.Base.serializer p -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLGen.parse_bounded_vlgen vmin vmax pk s)
{ "end_col": 99, "end_line": 34, "start_col": 2, "start_line": 24 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let poly128 = p:poly{degree p < 128}
let poly128 =
false
null
false
p: poly{degree p < 128}
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.b2t", "Prims.op_LessThan", "Vale.Math.Poly2_s.degree" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val poly128 : Type0
[]
Vale.AES.GHash.poly128
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 36, "end_line": 25, "start_col": 14, "start_line": 25 }
Prims.Tot
val ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let ghash_incremental0 (h:quad32) (y_prev:quad32) (x:seq quad32) : quad32 = if length x > 0 then ghash_incremental h y_prev x else y_prev
val ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32 let ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32 =
false
null
false
if length x > 0 then ghash_incremental h y_prev x else y_prev
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.op_GreaterThan", "FStar.Seq.Base.length", "Vale.AES.GHash.ghash_incremental", "Prims.bool" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_degree (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Lemma (requires degree h < 128 /\ degree init < 128) (ensures degree (ghash_poly h init data j k) < 128) (decreases (k - j)) [SMTPat (ghash_poly h init data j k)] val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let lemma_add_manip (x y z:poly) : Lemma (x +. y +. z == x +. z +. y) = calc (==) { x +. y +. z; == { lemma_add_associate x y z } x +. (y +. z); == { lemma_add_commute y z } x +. (z +. y); == { lemma_add_associate x z y } x +. z +. y; }; () let rec ghash_incremental_def (h_LE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_LE y_prev (all_but_last x) in let x_i = last x in let xor_LE = quad32_xor y_i_minus_1 x_i in gf128_mul_LE xor_LE h_LE [@"opaque_to_smt"] let ghash_incremental = opaque_make ghash_incremental_def irreducible let ghash_incremental_reveal = opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def val lemma_ghash_incremental_poly (h_LE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (ensures of_quad32 (reverse_bytes_quad32 (ghash_incremental h_LE y_prev x)) == ghash_poly (of_quad32 (reverse_bytes_quad32 h_LE)) (of_quad32 (reverse_bytes_quad32 y_prev)) (fun_seq_quad32_LE_poly128 x) 0 (length x) ) // avoids need for extra fuel val lemma_ghash_incremental_def_0 (h_LE:quad32) (y_prev:quad32) (x:seq quad32) : Lemma (requires length x == 0) (ensures ghash_incremental_def h_LE y_prev x == y_prev) [SMTPat (ghash_incremental_def h_LE y_prev x)] val ghash_incremental_to_ghash (h:quad32) (x:seq quad32) : Lemma (requires length x > 0) (ensures ghash_incremental h (Mkfour 0 0 0 0) x == ghash_LE h x) (decreases %[length x]) val lemma_hash_append (h:quad32) (y_prev:quad32) (a b:ghash_plain_LE) : Lemma (ensures ghash_incremental h y_prev (append a b) == (let y_a = ghash_incremental h y_prev a in ghash_incremental h y_a b)) (decreases %[length b])
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental0 (h y_prev: quad32) (x: seq quad32) : quad32
[]
Vale.AES.GHash.ghash_incremental0
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Def.Types_s.quad32 -> y_prev: Vale.Def.Types_s.quad32 -> x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
{ "end_col": 63, "end_line": 139, "start_col": 2, "start_line": 139 }
Prims.Tot
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let ghash_incremental = opaque_make ghash_incremental_def
let ghash_incremental =
false
null
false
opaque_make ghash_incremental_def
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total" ]
[ "Vale.Def.Opaque_s.opaque_make", "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.AES.GHash.ghash_incremental_def" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_degree (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Lemma (requires degree h < 128 /\ degree init < 128) (ensures degree (ghash_poly h init data j k) < 128) (decreases (k - j)) [SMTPat (ghash_poly h init data j k)] val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let lemma_add_manip (x y z:poly) : Lemma (x +. y +. z == x +. z +. y) = calc (==) { x +. y +. z; == { lemma_add_associate x y z } x +. (y +. z); == { lemma_add_commute y z } x +. (z +. y); == { lemma_add_associate x z y } x +. z +. y; }; () let rec ghash_incremental_def (h_LE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_LE y_prev (all_but_last x) in let x_i = last x in let xor_LE = quad32_xor y_i_minus_1 x_i in
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental : _: Vale.Def.Types_s.quad32 -> _: Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Prims.Tot Vale.Def.Types_s.quad32
[]
Vale.AES.GHash.ghash_incremental
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Vale.Def.Types_s.quad32 -> _: Vale.Def.Types_s.quad32 -> _: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Prims.Tot Vale.Def.Types_s.quad32
{ "end_col": 76, "end_line": 109, "start_col": 43, "start_line": 109 }
FStar.Pervasives.Lemma
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let ghash_incremental_reveal = opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def
let ghash_incremental_reveal =
false
null
true
opaque_revealer (`%ghash_incremental) ghash_incremental ghash_incremental_def
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "lemma" ]
[ "Vale.Def.Opaque_s.opaque_revealer", "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Vale.AES.GHash.ghash_incremental", "Vale.AES.GHash.ghash_incremental_def" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_degree (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Lemma (requires degree h < 128 /\ degree init < 128) (ensures degree (ghash_poly h init data j k) < 128) (decreases (k - j)) [SMTPat (ghash_poly h init data j k)] val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let lemma_add_manip (x y z:poly) : Lemma (x +. y +. z == x +. z +. y) = calc (==) { x +. y +. z; == { lemma_add_associate x y z } x +. (y +. z); == { lemma_add_commute y z } x +. (z +. y); == { lemma_add_associate x z y } x +. z +. y; }; () let rec ghash_incremental_def (h_LE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_LE y_prev (all_but_last x) in let x_i = last x in let xor_LE = quad32_xor y_i_minus_1 x_i in gf128_mul_LE xor_LE h_LE
false
false
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental_reveal : _: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.GHash.ghash_incremental == Vale.AES.GHash.ghash_incremental_def)
[]
Vale.AES.GHash.ghash_incremental_reveal
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Vale.AES.GHash.ghash_incremental == Vale.AES.GHash.ghash_incremental_def)
{ "end_col": 120, "end_line": 110, "start_col": 43, "start_line": 110 }
Prims.Tot
val fun_seq_quad32_LE_poly128 (s: seq quad32) : (int -> poly128)
[ { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero
val fun_seq_quad32_LE_poly128 (s: seq quad32) : (int -> poly128) let fun_seq_quad32_LE_poly128 (s: seq quad32) : (int -> poly128) =
false
null
false
fun (i: int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.int", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Seq.Base.length", "Vale.Math.Poly2.Bits_s.of_quad32", "Vale.Def.Types_s.reverse_bytes_quad32", "FStar.Seq.Base.index", "Prims.bool", "Vale.Math.Poly2_s.zero", "Vale.AES.GHash.poly128" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128}
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val fun_seq_quad32_LE_poly128 (s: seq quad32) : (int -> poly128)
[]
Vale.AES.GHash.fun_seq_quad32_LE_poly128
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> _: Prims.int -> Vale.AES.GHash.poly128
{ "end_col": 102, "end_line": 28, "start_col": 2, "start_line": 28 }
Prims.Tot
val ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j))
[ { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h
val ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j)) let rec ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j)) =
false
null
false
if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total", "" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash.poly128", "Prims.op_LessThanOrEqual", "Prims.bool", "Vale.AES.GF128.gf128_mul_rev", "Vale.Math.Poly2.op_Plus_Dot", "Vale.AES.GHash.ghash_poly", "Prims.op_Subtraction" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_poly (h init: poly) (data: (int -> poly128)) (j k: int) : Tot poly (decreases (k - j))
[ "recursion" ]
Vale.AES.GHash.ghash_poly
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> init: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash.poly128) -> j: Prims.int -> k: Prims.int -> Prims.Tot Vale.Math.Poly2_s.poly
{ "end_col": 68, "end_line": 32, "start_col": 2, "start_line": 31 }
Prims.Tot
val ghash_incremental_def (h_LE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x])
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let rec ghash_incremental_def (h_LE:quad32) (y_prev:quad32) (x:seq quad32) : Tot quad32 (decreases %[length x]) = if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_LE y_prev (all_but_last x) in let x_i = last x in let xor_LE = quad32_xor y_i_minus_1 x_i in gf128_mul_LE xor_LE h_LE
val ghash_incremental_def (h_LE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x]) let rec ghash_incremental_def (h_LE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x]) =
false
null
false
if length x = 0 then y_prev else let y_i_minus_1 = ghash_incremental_def h_LE y_prev (all_but_last x) in let x_i = last x in let xor_LE = quad32_xor y_i_minus_1 x_i in gf128_mul_LE xor_LE h_LE
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total", "" ]
[ "Vale.Def.Types_s.quad32", "FStar.Seq.Base.seq", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "Prims.bool", "Vale.AES.GHash_s.gf128_mul_LE", "Vale.Def.Types_s.quad32_xor", "FStar.Seq.Properties.last", "Vale.AES.GHash.ghash_incremental_def", "Vale.Lib.Seqs_s.all_but_last" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_degree (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Lemma (requires degree h < 128 /\ degree init < 128) (ensures degree (ghash_poly h init data j k) < 128) (decreases (k - j)) [SMTPat (ghash_poly h init data j k)] val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let lemma_add_manip (x y z:poly) : Lemma (x +. y +. z == x +. z +. y) = calc (==) { x +. y +. z; == { lemma_add_associate x y z } x +. (y +. z); == { lemma_add_commute y z } x +. (z +. y); == { lemma_add_associate x z y } x +. z +. y; }; ()
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_incremental_def (h_LE y_prev: quad32) (x: seq quad32) : Tot quad32 (decreases %[length x])
[ "recursion" ]
Vale.AES.GHash.ghash_incremental_def
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h_LE: Vale.Def.Types_s.quad32 -> y_prev: Vale.Def.Types_s.quad32 -> x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> Prims.Tot Vale.Def.Types_s.quad32
{ "end_col": 26, "end_line": 108, "start_col": 2, "start_line": 104 }
Prims.Tot
val hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6
val hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0 let hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0 =
false
null
false
let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total" ]
[ "FStar.Seq.Base.seq", "Vale.Def.Types_s.quad32", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.Seq.Base.length", "Prims.eq2", "FStar.Seq.Base.index", "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.Bits_s.of_quad32", "Vale.AES.GHash.gf128_power", "Prims.op_Equality", "Vale.Def.Words_s.four", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Prop_s.prop0" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n))
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hkeys_reqs_priv (hkeys: seq quad32) (h_BE: quad32) : Vale.Def.Prop_s.prop0
[]
Vale.AES.GHash.hkeys_reqs_priv
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hkeys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> h_BE: Vale.Def.Types_s.quad32 -> Vale.Def.Prop_s.prop0
{ "end_col": 46, "end_line": 53, "start_col": 3, "start_line": 43 }
Prims.Tot
val ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p
val ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly let rec ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly =
false
null
false
let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash.poly128", "Prims.nat", "Prims.op_Equality", "Vale.Math.Poly2.op_Star_Dot", "Vale.Math.Poly2.op_Plus_Dot", "Prims.bool", "Vale.AES.GHash.ghash_unroll", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.AES.GHash.gf128_power" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE)
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_unroll (h prev: poly) (data: (int -> poly128)) (k: int) (m n: nat) : poly
[ "recursion" ]
Vale.AES.GHash.ghash_unroll
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash.poly128) -> k: Prims.int -> m: Prims.nat -> n: Prims.nat -> Vale.Math.Poly2_s.poly
{ "end_col": 54, "end_line": 63, "start_col": 90, "start_line": 59 }
Prims.Tot
val ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p
val ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly let rec ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly =
false
null
false
let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "total" ]
[ "Vale.Math.Poly2_s.poly", "Prims.int", "Vale.AES.GHash.poly128", "Prims.nat", "Prims.op_Equality", "Vale.Math.Poly2.op_Star_Dot", "Prims.bool", "Vale.Math.Poly2.op_Plus_Dot", "Vale.AES.GHash.ghash_unroll_back", "Prims.op_Subtraction", "Vale.AES.GHash.gf128_power", "Prims.op_Addition" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p
false
true
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ghash_unroll_back (h prev: poly) (data: (int -> poly128)) (k: int) (n m: nat) : poly
[ "recursion" ]
Vale.AES.GHash.ghash_unroll_back
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: Vale.Math.Poly2_s.poly -> prev: Vale.Math.Poly2_s.poly -> data: (_: Prims.int -> Vale.AES.GHash.poly128) -> k: Prims.int -> n: Prims.nat -> m: Prims.nat -> Vale.Math.Poly2_s.poly
{ "end_col": 53, "end_line": 71, "start_col": 95, "start_line": 66 }
FStar.Pervasives.Lemma
val lemma_add_manip (x y z: poly) : Lemma (x +. y +. z == x +. z +. y)
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Words", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.OptPublic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs_s", "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.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GHash_s", "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.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 } ]
false
let lemma_add_manip (x y z:poly) : Lemma (x +. y +. z == x +. z +. y) = calc (==) { x +. y +. z; == { lemma_add_associate x y z } x +. (y +. z); == { lemma_add_commute y z } x +. (z +. y); == { lemma_add_associate x z y } x +. z +. y; }; ()
val lemma_add_manip (x y z: poly) : Lemma (x +. y +. z == x +. z +. y) let lemma_add_manip (x y z: poly) : Lemma (x +. y +. z == x +. z +. y) =
false
null
true
calc ( == ) { x +. y +. z; ( == ) { lemma_add_associate x y z } x +. (y +. z); ( == ) { lemma_add_commute y z } x +. (z +. y); ( == ) { lemma_add_associate x z y } x +. z +. y; }; ()
{ "checked_file": "Vale.AES.GHash.fsti.checked", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.Bits.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Lib.Seqs_s.fst.checked", "Vale.Lib.Seqs.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "Vale.Def.Opaque_s.fsti.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.OptPublic.fsti.checked", "Vale.AES.GHash_s.fst.checked", "Vale.AES.GF128_s.fsti.checked", "Vale.AES.GF128.fsti.checked", "Vale.AES.GCTR_s.fst.checked", "Vale.AES.GCM_helpers.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Vale.AES.GHash.fsti" }
[ "lemma" ]
[ "Vale.Math.Poly2_s.poly", "Prims.unit", "FStar.Calc.calc_finish", "Prims.eq2", "Vale.Math.Poly2.op_Plus_Dot", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Vale.Math.Poly2.lemma_add_associate", "Prims.squash", "Vale.Math.Poly2.lemma_add_commute", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
module Vale.AES.GHash open Vale.Def.Opaque_s open Vale.Def.Words_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GHash_s open Vale.AES.GF128_s open Vale.AES.GCTR_s open Vale.AES.GCM_helpers open Vale.Lib.Seqs_s open Vale.Lib.Seqs open FStar.Seq open Vale.Math.Poly2_s open Vale.Math.Poly2 open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2.Bits open Vale.AES.GF128 open FStar.Mul open FStar.Calc open Vale.AES.OptPublic #reset-options let poly128 = p:poly{degree p < 128} let fun_seq_quad32_LE_poly128 (s:seq quad32) : (int -> poly128) = fun (i:int) -> if 0 <= i && i < length s then of_quad32 (reverse_bytes_quad32 (index s i)) else zero let rec ghash_poly (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Tot poly (decreases (k - j)) = if k <= j then init else gf128_mul_rev (ghash_poly h init data j (k - 1) +. data (k - 1)) h val g_power (a:poly) (n:nat) : poly val lemma_g_power_1 (a:poly) : Lemma (g_power a 1 == a) val lemma_g_power_n (a:poly) (n:pos) : Lemma (g_power a (n + 1) == a *~ g_power a n) val gf128_power (h:poly) (n:nat) : poly val lemma_gf128_power (h:poly) (n:nat) : Lemma (gf128_power h n == shift_key_1 128 gf128_modulus_low_terms (g_power h n)) let hkeys_reqs_priv (hkeys:seq quad32) (h_BE:quad32) : Vale.Def.Prop_s.prop0 = let h = of_quad32 (reverse_bytes_quad32 (reverse_bytes_quad32 h_BE)) in length hkeys >= 8 /\ index hkeys 2 == h_BE /\ of_quad32 (index hkeys 0) == gf128_power h 1 /\ of_quad32 (index hkeys 1) == gf128_power h 2 /\ of_quad32 (index hkeys 3) == gf128_power h 3 /\ of_quad32 (index hkeys 4) == gf128_power h 4 /\ index hkeys 5 = Mkfour 0 0 0 0 /\ of_quad32 (index hkeys 6) == gf128_power h 5 /\ of_quad32 (index hkeys 7) == gf128_power h 6 val lemma_hkeys_reqs_pub_priv (hkeys:seq quad32) (h_BE:quad32) : Lemma (hkeys_reqs_pub hkeys h_BE <==> hkeys_reqs_priv hkeys h_BE) // Unrolled series of n ghash computations let rec ghash_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m n:nat) : poly = let d = data (k + m) in let p = gf128_power h (n + 1) in if m = 0 then (prev +. d) *. p else ghash_unroll h prev data k (m - 1) (n + 1) +. d *. p // Unrolled series of n ghash computations in reverse order (last to first) let rec ghash_unroll_back (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n m:nat) : poly = let d = data (k + (n - 1 - m)) in let p = gf128_power h (m + 1) in let v = if m = n - 1 then prev +. d else d in if m = 0 then v *. p else ghash_unroll_back h prev data k n (m - 1) +. v *. p val lemma_ghash_unroll_back_forward (h:poly) (prev:poly) (data:int -> poly128) (k:int) (n:nat) : Lemma (ghash_unroll h prev data k n 0 == ghash_unroll_back h prev data k (n + 1) n) val lemma_ghash_poly_degree (h:poly) (init:poly) (data:int -> poly128) (j:int) (k:int) : Lemma (requires degree h < 128 /\ degree init < 128) (ensures degree (ghash_poly h init data j k) < 128) (decreases (k - j)) [SMTPat (ghash_poly h init data j k)] val lemma_ghash_poly_of_unroll (h:poly) (prev:poly) (data:int -> poly128) (k:int) (m:nat) : Lemma (requires degree h < 128 /\ degree prev < 128) (ensures mod_rev 128 (ghash_unroll h prev data k m 0) gf128_modulus == ghash_poly h prev data k (k + m + 1) ) let lemma_add_manip (x y z:poly) : Lemma (x +. y +. z == x +. z +. y)
false
false
Vale.AES.GHash.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val lemma_add_manip (x y z: poly) : Lemma (x +. y +. z == x +. z +. y)
[]
Vale.AES.GHash.lemma_add_manip
{ "file_name": "vale/code/crypto/aes/Vale.AES.GHash.fsti", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
x: Vale.Math.Poly2_s.poly -> y: Vale.Math.Poly2_s.poly -> z: Vale.Math.Poly2_s.poly -> FStar.Pervasives.Lemma (ensures x +. y +. z == x +. z +. y)
{ "end_col": 4, "end_line": 101, "start_col": 2, "start_line": 92 }
Prims.Tot
val synth_u32_le (x: bounded_integer 4) : Tot U32.t
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_u32_le (x: bounded_integer 4) : Tot U32.t = x
val synth_u32_le (x: bounded_integer 4) : Tot U32.t let synth_u32_le (x: bounded_integer 4) : Tot U32.t =
false
null
false
x
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.BoundedInt.bounded_integer", "FStar.UInt32.t" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i) let parse_bounded_integer_spec i input = parser_kind_prop_equiv (parse_bounded_integer_kind i) (parse_bounded_integer i); M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); match parse (parse_bounded_integer i) input with | None -> () | Some (y, consumed) -> let input' = Seq.slice input 0 i in E.lemma_be_to_n_is_bounded input'; parse_strong_prefix (parse_bounded_integer i) input input' let serialize_bounded_integer' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> let res = E.n_to_be sz (U32.v x) in res ) let serialize_bounded_integer_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer sz) (serialize_bounded_integer' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) = serialize_bounded_integer_correct sz; serialize_bounded_integer' sz let serialize_bounded_integer_spec sz x = () let bounded_integer_of_le (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_le_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.le_to_n b) let bounded_integer_of_le_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (bounded_integer_of_le i b1 == bounded_integer_of_le i b2 ==> Seq.equal b1 b2) = if bounded_integer_of_le i b1 = bounded_integer_of_le i b2 then begin E.lemma_le_to_n_is_bounded b1; E.lemma_le_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.le_to_n b1)) == E.le_to_n b1); assert (U32.v (U32.uint_to_t (E.le_to_n b2)) == E.le_to_n b2); assert (E.le_to_n b1 == E.le_to_n b2); E.le_to_n_inj b1 b2 end else () #pop-options let bounded_integer_of_le_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (bounded_integer_of_le i)) = Classical.forall_intro_2 (bounded_integer_of_le_injective' i) let parse_bounded_integer_le i = bounded_integer_of_le_injective i; make_total_constant_size_parser i (bounded_integer i) (bounded_integer_of_le i) inline_for_extraction let synth_u16_le (x: bounded_integer 2) : Tot U16.t = Cast.uint32_to_uint16 x let synth_u16_le_injective : squash (synth_injective synth_u16_le) = () let parse_u16_le = parse_bounded_integer_le 2 `parse_synth` synth_u16_le inline_for_extraction let synth_u32_le (x: bounded_integer 4)
false
false
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_u32_le (x: bounded_integer 4) : Tot U32.t
[]
LowParse.Spec.BoundedInt.synth_u32_le
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: LowParse.Spec.BoundedInt.bounded_integer 4 -> FStar.UInt32.t
{ "end_col": 3, "end_line": 159, "start_col": 2, "start_line": 159 }
Prims.Tot
val parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i))
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i)
val parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) =
false
null
false
decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i)
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.Combinators.make_total_constant_size_parser", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.decode_bounded_integer", "Prims.unit", "LowParse.Spec.BoundedInt.decode_bounded_integer_injective", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size)
false
false
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i))
[]
LowParse.Spec.BoundedInt.parse_bounded_integer
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
i: LowParse.Spec.BoundedInt.integer_size -> LowParse.Spec.Base.parser (LowParse.Spec.BoundedInt.parse_bounded_integer_kind i) (LowParse.Spec.BoundedInt.bounded_integer i)
{ "end_col": 82, "end_line": 64, "start_col": 2, "start_line": 63 }
Prims.Tot
val parse_bounded_integer_le (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i))
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_integer_le i = bounded_integer_of_le_injective i; make_total_constant_size_parser i (bounded_integer i) (bounded_integer_of_le i)
val parse_bounded_integer_le (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) let parse_bounded_integer_le i =
false
null
false
bounded_integer_of_le_injective i; make_total_constant_size_parser i (bounded_integer i) (bounded_integer_of_le i)
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.Combinators.make_total_constant_size_parser", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.bounded_integer_of_le", "Prims.unit", "LowParse.Spec.BoundedInt.bounded_integer_of_le_injective", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i) let parse_bounded_integer_spec i input = parser_kind_prop_equiv (parse_bounded_integer_kind i) (parse_bounded_integer i); M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); match parse (parse_bounded_integer i) input with | None -> () | Some (y, consumed) -> let input' = Seq.slice input 0 i in E.lemma_be_to_n_is_bounded input'; parse_strong_prefix (parse_bounded_integer i) input input' let serialize_bounded_integer' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> let res = E.n_to_be sz (U32.v x) in res ) let serialize_bounded_integer_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer sz) (serialize_bounded_integer' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) = serialize_bounded_integer_correct sz; serialize_bounded_integer' sz let serialize_bounded_integer_spec sz x = () let bounded_integer_of_le (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_le_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.le_to_n b) let bounded_integer_of_le_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (bounded_integer_of_le i b1 == bounded_integer_of_le i b2 ==> Seq.equal b1 b2) = if bounded_integer_of_le i b1 = bounded_integer_of_le i b2 then begin E.lemma_le_to_n_is_bounded b1; E.lemma_le_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.le_to_n b1)) == E.le_to_n b1); assert (U32.v (U32.uint_to_t (E.le_to_n b2)) == E.le_to_n b2); assert (E.le_to_n b1 == E.le_to_n b2); E.le_to_n_inj b1 b2 end else () #pop-options let bounded_integer_of_le_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (bounded_integer_of_le i)) = Classical.forall_intro_2 (bounded_integer_of_le_injective' i) let parse_bounded_integer_le
false
false
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_integer_le (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i))
[]
LowParse.Spec.BoundedInt.parse_bounded_integer_le
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
i: LowParse.Spec.BoundedInt.integer_size -> LowParse.Spec.Base.parser (LowParse.Spec.BoundedInt.parse_bounded_integer_kind i) (LowParse.Spec.BoundedInt.bounded_integer i)
{ "end_col": 81, "end_line": 143, "start_col": 2, "start_line": 142 }
Prims.Tot
val synth_u16_le (x: bounded_integer 2) : Tot U16.t
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_u16_le (x: bounded_integer 2) : Tot U16.t = Cast.uint32_to_uint16 x
val synth_u16_le (x: bounded_integer 2) : Tot U16.t let synth_u16_le (x: bounded_integer 2) : Tot U16.t =
false
null
false
Cast.uint32_to_uint16 x
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.BoundedInt.bounded_integer", "FStar.Int.Cast.uint32_to_uint16", "FStar.UInt16.t" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i) let parse_bounded_integer_spec i input = parser_kind_prop_equiv (parse_bounded_integer_kind i) (parse_bounded_integer i); M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); match parse (parse_bounded_integer i) input with | None -> () | Some (y, consumed) -> let input' = Seq.slice input 0 i in E.lemma_be_to_n_is_bounded input'; parse_strong_prefix (parse_bounded_integer i) input input' let serialize_bounded_integer' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> let res = E.n_to_be sz (U32.v x) in res ) let serialize_bounded_integer_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer sz) (serialize_bounded_integer' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) = serialize_bounded_integer_correct sz; serialize_bounded_integer' sz let serialize_bounded_integer_spec sz x = () let bounded_integer_of_le (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_le_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.le_to_n b) let bounded_integer_of_le_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (bounded_integer_of_le i b1 == bounded_integer_of_le i b2 ==> Seq.equal b1 b2) = if bounded_integer_of_le i b1 = bounded_integer_of_le i b2 then begin E.lemma_le_to_n_is_bounded b1; E.lemma_le_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.le_to_n b1)) == E.le_to_n b1); assert (U32.v (U32.uint_to_t (E.le_to_n b2)) == E.le_to_n b2); assert (E.le_to_n b1 == E.le_to_n b2); E.le_to_n_inj b1 b2 end else () #pop-options let bounded_integer_of_le_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (bounded_integer_of_le i)) = Classical.forall_intro_2 (bounded_integer_of_le_injective' i) let parse_bounded_integer_le i = bounded_integer_of_le_injective i; make_total_constant_size_parser i (bounded_integer i) (bounded_integer_of_le i) inline_for_extraction let synth_u16_le (x: bounded_integer 2)
false
false
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_u16_le (x: bounded_integer 2) : Tot U16.t
[]
LowParse.Spec.BoundedInt.synth_u16_le
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: LowParse.Spec.BoundedInt.bounded_integer 2 -> FStar.UInt16.t
{ "end_col": 25, "end_line": 149, "start_col": 2, "start_line": 149 }
Prims.Tot
val serialize_bounded_integer_le (sz: integer_size) : Tot (serializer (parse_bounded_integer_le sz))
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_integer_le sz = serialize_bounded_integer_le_correct sz; serialize_bounded_integer_le' sz
val serialize_bounded_integer_le (sz: integer_size) : Tot (serializer (parse_bounded_integer_le sz)) let serialize_bounded_integer_le sz =
false
null
false
serialize_bounded_integer_le_correct sz; serialize_bounded_integer_le' sz
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le'", "Prims.unit", "LowParse.Spec.BoundedInt.serialize_bounded_integer_le_correct", "LowParse.Spec.Base.serializer", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_le" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i) let parse_bounded_integer_spec i input = parser_kind_prop_equiv (parse_bounded_integer_kind i) (parse_bounded_integer i); M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); match parse (parse_bounded_integer i) input with | None -> () | Some (y, consumed) -> let input' = Seq.slice input 0 i in E.lemma_be_to_n_is_bounded input'; parse_strong_prefix (parse_bounded_integer i) input input' let serialize_bounded_integer' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> let res = E.n_to_be sz (U32.v x) in res ) let serialize_bounded_integer_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer sz) (serialize_bounded_integer' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) = serialize_bounded_integer_correct sz; serialize_bounded_integer' sz let serialize_bounded_integer_spec sz x = () let bounded_integer_of_le (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_le_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.le_to_n b) let bounded_integer_of_le_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (bounded_integer_of_le i b1 == bounded_integer_of_le i b2 ==> Seq.equal b1 b2) = if bounded_integer_of_le i b1 = bounded_integer_of_le i b2 then begin E.lemma_le_to_n_is_bounded b1; E.lemma_le_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.le_to_n b1)) == E.le_to_n b1); assert (U32.v (U32.uint_to_t (E.le_to_n b2)) == E.le_to_n b2); assert (E.le_to_n b1 == E.le_to_n b2); E.le_to_n_inj b1 b2 end else () #pop-options let bounded_integer_of_le_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (bounded_integer_of_le i)) = Classical.forall_intro_2 (bounded_integer_of_le_injective' i) let parse_bounded_integer_le i = bounded_integer_of_le_injective i; make_total_constant_size_parser i (bounded_integer i) (bounded_integer_of_le i) inline_for_extraction let synth_u16_le (x: bounded_integer 2) : Tot U16.t = Cast.uint32_to_uint16 x let synth_u16_le_injective : squash (synth_injective synth_u16_le) = () let parse_u16_le = parse_bounded_integer_le 2 `parse_synth` synth_u16_le inline_for_extraction let synth_u32_le (x: bounded_integer 4) : Tot U32.t = x let parse_u32_le = parse_bounded_integer_le 4 `parse_synth` synth_u32_le let serialize_bounded_integer_le' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> E.n_to_le sz (U32.v x) ) #push-options "--z3rlimit 16" let serialize_bounded_integer_le_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer_le sz) (serialize_bounded_integer_le' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer_le' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer_le sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf #pop-options let serialize_bounded_integer_le
false
false
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_integer_le (sz: integer_size) : Tot (serializer (parse_bounded_integer_le sz))
[]
LowParse.Spec.BoundedInt.serialize_bounded_integer_le
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: LowParse.Spec.BoundedInt.integer_size -> LowParse.Spec.Base.serializer (LowParse.Spec.BoundedInt.parse_bounded_integer_le sz)
{ "end_col": 34, "end_line": 193, "start_col": 2, "start_line": 192 }
Prims.Tot
val serialize_bounded_integer (sz: integer_size) : Tot (serializer (parse_bounded_integer sz))
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) = serialize_bounded_integer_correct sz; serialize_bounded_integer' sz
val serialize_bounded_integer (sz: integer_size) : Tot (serializer (parse_bounded_integer sz)) let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) =
false
null
false
serialize_bounded_integer_correct sz; serialize_bounded_integer' sz
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.BoundedInt.serialize_bounded_integer'", "Prims.unit", "LowParse.Spec.BoundedInt.serialize_bounded_integer_correct", "LowParse.Spec.Base.serializer", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i) let parse_bounded_integer_spec i input = parser_kind_prop_equiv (parse_bounded_integer_kind i) (parse_bounded_integer i); M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); match parse (parse_bounded_integer i) input with | None -> () | Some (y, consumed) -> let input' = Seq.slice input 0 i in E.lemma_be_to_n_is_bounded input'; parse_strong_prefix (parse_bounded_integer i) input input' let serialize_bounded_integer' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> let res = E.n_to_be sz (U32.v x) in res ) let serialize_bounded_integer_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer sz) (serialize_bounded_integer' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf let serialize_bounded_integer sz
false
false
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_integer (sz: integer_size) : Tot (serializer (parse_bounded_integer sz))
[]
LowParse.Spec.BoundedInt.serialize_bounded_integer
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: LowParse.Spec.BoundedInt.integer_size -> LowParse.Spec.Base.serializer (LowParse.Spec.BoundedInt.parse_bounded_integer sz)
{ "end_col": 31, "end_line": 104, "start_col": 2, "start_line": 103 }
Prims.Tot
val parse_u16_le : parser parse_u16_kind U16.t
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_u16_le = parse_bounded_integer_le 2 `parse_synth` synth_u16_le
val parse_u16_le : parser parse_u16_kind U16.t let parse_u16_le =
false
null
false
(parse_bounded_integer_le 2) `parse_synth` synth_u16_le
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "FStar.UInt16.t", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.synth_u16_le" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i) let parse_bounded_integer_spec i input = parser_kind_prop_equiv (parse_bounded_integer_kind i) (parse_bounded_integer i); M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); match parse (parse_bounded_integer i) input with | None -> () | Some (y, consumed) -> let input' = Seq.slice input 0 i in E.lemma_be_to_n_is_bounded input'; parse_strong_prefix (parse_bounded_integer i) input input' let serialize_bounded_integer' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> let res = E.n_to_be sz (U32.v x) in res ) let serialize_bounded_integer_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer sz) (serialize_bounded_integer' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) = serialize_bounded_integer_correct sz; serialize_bounded_integer' sz let serialize_bounded_integer_spec sz x = () let bounded_integer_of_le (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_le_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.le_to_n b) let bounded_integer_of_le_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (bounded_integer_of_le i b1 == bounded_integer_of_le i b2 ==> Seq.equal b1 b2) = if bounded_integer_of_le i b1 = bounded_integer_of_le i b2 then begin E.lemma_le_to_n_is_bounded b1; E.lemma_le_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.le_to_n b1)) == E.le_to_n b1); assert (U32.v (U32.uint_to_t (E.le_to_n b2)) == E.le_to_n b2); assert (E.le_to_n b1 == E.le_to_n b2); E.le_to_n_inj b1 b2 end else () #pop-options let bounded_integer_of_le_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (bounded_integer_of_le i)) = Classical.forall_intro_2 (bounded_integer_of_le_injective' i) let parse_bounded_integer_le i = bounded_integer_of_le_injective i; make_total_constant_size_parser i (bounded_integer i) (bounded_integer_of_le i) inline_for_extraction let synth_u16_le (x: bounded_integer 2) : Tot U16.t = Cast.uint32_to_uint16 x let synth_u16_le_injective : squash (synth_injective synth_u16_le) = ()
false
true
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_u16_le : parser parse_u16_kind U16.t
[]
LowParse.Spec.BoundedInt.parse_u16_le
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser LowParse.Spec.Int.parse_u16_kind FStar.UInt16.t
{ "end_col": 72, "end_line": 153, "start_col": 19, "start_line": 153 }
Prims.Tot
val parse_u32_le : parser parse_u32_kind U32.t
[ { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "M" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators // for make_total_constant_size_parser_precond", "short_module": null }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_u32_le = parse_bounded_integer_le 4 `parse_synth` synth_u32_le
val parse_u32_le : parser parse_u32_kind U32.t let parse_u32_le =
false
null
false
(parse_bounded_integer_le 4) `parse_synth` synth_u32_le
{ "checked_file": "LowParse.Spec.BoundedInt.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.BoundedInt.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "FStar.UInt32.t", "LowParse.Spec.BoundedInt.parse_bounded_integer_le", "LowParse.Spec.BoundedInt.synth_u32_le" ]
[]
module LowParse.Spec.BoundedInt open LowParse.Spec.Combinators // for make_total_constant_size_parser_precond module Seq = FStar.Seq module E = FStar.Endianness module U8 = FStar.UInt8 module U16 = FStar.UInt16 module U32 = FStar.UInt32 module M = LowParse.Math module Cast = FStar.Int.Cast (* bounded integers *) let integer_size_values i = () let bounded_integer_prop_equiv (i: integer_size) (u: U32.t) : Lemma (bounded_integer_prop i u <==> U32.v u < pow2 (8 * i)) = assert_norm (pow2 8 == 256); assert_norm (pow2 16 == 65536); assert_norm (pow2 24 == 16777216); assert_norm (pow2 32 == 4294967296) #push-options "--z3rlimit 16" let decode_bounded_integer (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_be_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.be_to_n b) let decode_bounded_integer_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (decode_bounded_integer i b1 == decode_bounded_integer i b2 ==> Seq.equal b1 b2) = if decode_bounded_integer i b1 = decode_bounded_integer i b2 then begin E.lemma_be_to_n_is_bounded b1; E.lemma_be_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.be_to_n b1)) == E.be_to_n b1); assert (U32.v (U32.uint_to_t (E.be_to_n b2)) == E.be_to_n b2); assert (E.be_to_n b1 == E.be_to_n b2); E.be_to_n_inj b1 b2 end else () let decode_bounded_integer_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (decode_bounded_integer i)) = Classical.forall_intro_2 (decode_bounded_integer_injective' i) let parse_bounded_integer (i: integer_size) : Tot (parser (parse_bounded_integer_kind i) (bounded_integer i)) = decode_bounded_integer_injective i; make_total_constant_size_parser i (bounded_integer i) (decode_bounded_integer i) let parse_bounded_integer_spec i input = parser_kind_prop_equiv (parse_bounded_integer_kind i) (parse_bounded_integer i); M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); match parse (parse_bounded_integer i) input with | None -> () | Some (y, consumed) -> let input' = Seq.slice input 0 i in E.lemma_be_to_n_is_bounded input'; parse_strong_prefix (parse_bounded_integer i) input input' let serialize_bounded_integer' (sz: integer_size) : Tot (bare_serializer (bounded_integer sz)) = (fun (x: bounded_integer sz) -> let res = E.n_to_be sz (U32.v x) in res ) let serialize_bounded_integer_correct (sz: integer_size) : Lemma (serializer_correct (parse_bounded_integer sz) (serialize_bounded_integer' sz)) = let prf (x: bounded_integer sz) : Lemma ( let res = serialize_bounded_integer' sz x in Seq.length res == (sz <: nat) /\ parse (parse_bounded_integer sz) res == Some (x, (sz <: nat)) ) = () in Classical.forall_intro prf let serialize_bounded_integer sz : Tot (serializer (parse_bounded_integer sz)) = serialize_bounded_integer_correct sz; serialize_bounded_integer' sz let serialize_bounded_integer_spec sz x = () let bounded_integer_of_le (i: integer_size) (b: bytes { Seq.length b == i } ) : GTot (bounded_integer i) = E.lemma_le_to_n_is_bounded b; M.pow2_le_compat 32 (8 `FStar.Mul.op_Star` i); U32.uint_to_t (E.le_to_n b) let bounded_integer_of_le_injective' (i: integer_size) (b1: bytes { Seq.length b1 == i } ) (b2: bytes { Seq.length b2 == i } ) : Lemma (bounded_integer_of_le i b1 == bounded_integer_of_le i b2 ==> Seq.equal b1 b2) = if bounded_integer_of_le i b1 = bounded_integer_of_le i b2 then begin E.lemma_le_to_n_is_bounded b1; E.lemma_le_to_n_is_bounded b2; assert (U32.v (U32.uint_to_t (E.le_to_n b1)) == E.le_to_n b1); assert (U32.v (U32.uint_to_t (E.le_to_n b2)) == E.le_to_n b2); assert (E.le_to_n b1 == E.le_to_n b2); E.le_to_n_inj b1 b2 end else () #pop-options let bounded_integer_of_le_injective (i: integer_size) : Lemma (make_total_constant_size_parser_precond i (bounded_integer i) (bounded_integer_of_le i)) = Classical.forall_intro_2 (bounded_integer_of_le_injective' i) let parse_bounded_integer_le i = bounded_integer_of_le_injective i; make_total_constant_size_parser i (bounded_integer i) (bounded_integer_of_le i) inline_for_extraction let synth_u16_le (x: bounded_integer 2) : Tot U16.t = Cast.uint32_to_uint16 x let synth_u16_le_injective : squash (synth_injective synth_u16_le) = () let parse_u16_le = parse_bounded_integer_le 2 `parse_synth` synth_u16_le inline_for_extraction let synth_u32_le (x: bounded_integer 4) : Tot U32.t = x
false
true
LowParse.Spec.BoundedInt.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_u32_le : parser parse_u32_kind U32.t
[]
LowParse.Spec.BoundedInt.parse_u32_le
{ "file_name": "src/lowparse/LowParse.Spec.BoundedInt.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser LowParse.Spec.Int.parse_u32_kind FStar.UInt32.t
{ "end_col": 72, "end_line": 161, "start_col": 19, "start_line": 161 }