file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.bn_mod_slow_ctx_st | val bn_mod_slow_ctx_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 243,
"start_col": 0,
"start_line": 231
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
inline_for_extraction noextract
val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len
let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.int",
"Hacl.Bignum.Definitions.bn_v",
"Prims.op_Modulus",
"Hacl.Bignum.MontArithmetic.bn_v_n"
] | [] | false | false | false | false | true | let bn_mod_slow_ctx_st (t: limb_t) (len: BN.meta_len t) =
| k: MA.pbn_mont_ctx t -> a: lbignum t (len +! len) -> res: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ live h a /\ live h res /\
disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k) | false |
|
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.mk_bn_mod_slow_safe | val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len | val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len | let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 156,
"start_col": 0,
"start_line": 146
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Hacl.Bignum.meta_len t -> bn_mod_slow: Hacl.Bignum.ModReduction.bn_mod_slow_st t len
-> Hacl.Bignum.SafeAPI.bn_mod_slow_safe_st t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.ModReduction.bn_mod_slow_st",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb",
"Prims.bool",
"Prims.unit",
"Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.memset",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Lib.IntTypes.range",
"Prims.op_Multiply",
"Lib.IntTypes.mk_int",
"Hacl.Spec.Bignum.Base.unsafe_size_from_limb",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Hacl.Bignum.Lib.bn_get_top_index",
"Hacl.Bignum.Montgomery.bn_check_modulus",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
| let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m
then
(SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res)
else memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.mk_bn_mod_inv_prime_safe | val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len | val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len | let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 227,
"start_col": 0,
"start_line": 217
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
inline_for_extraction noextract
val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: Hacl.Bignum.meta_len t -> bn_mod_exp: Hacl.Bignum.Exponentiation.bn_mod_exp_st t len
-> Hacl.Bignum.SafeAPI.bn_mod_inv_prime_safe_st t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Exponentiation.bn_mod_exp_st",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb",
"Prims.bool",
"Prims.unit",
"Hacl.Bignum.ModInv.mk_bn_mod_inv_prime",
"Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.memset",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Lib.IntTypes.range",
"Prims.op_Multiply",
"Lib.IntTypes.mk_int",
"Hacl.Spec.Bignum.Base.unsafe_size_from_limb",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Hacl.Bignum.Lib.bn_get_top_index",
"Hacl.Bignum.ModInv.bn_check_mod_inv_prime",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
| let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m
then
(SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res)
else memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.mk_bn_mod_exp_ctx | val mk_bn_mod_exp_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len ->
bn_mod_exp_ctx_st t len | val mk_bn_mod_exp_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len ->
bn_mod_exp_ctx_st t len | let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 292,
"start_col": 0,
"start_line": 289
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
inline_for_extraction noextract
val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len
let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k)
inline_for_extraction noextract
val bn_mod_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len ->
bn_mod_slow_ctx_st t len
let bn_mod_ctx #t len bn_mod_slow_precomp k a res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res
inline_for_extraction noextract
let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
bn_v h a < MA.bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n)
(as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
inline_for_extraction noextract
val mk_bn_mod_exp_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len ->
bn_mod_exp_ctx_st t len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: FStar.Ghost.erased (Hacl.Bignum.meta_len t) ->
bn_mod_exp_precomp: Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (FStar.Ghost.reveal len)
-> Hacl.Bignum.SafeAPI.bn_mod_exp_ctx_st t (FStar.Ghost.reveal len) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Ghost.erased",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st",
"FStar.Ghost.reveal",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__mu",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2",
"Prims.unit",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | false | let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res =
| let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.bn_mod_exp_ctx_st | val bn_mod_exp_ctx_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
bn_v h a < MA.bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n)
(as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 279,
"start_col": 0,
"start_line": 260
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
inline_for_extraction noextract
val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len
let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k)
inline_for_extraction noextract
val bn_mod_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len ->
bn_mod_slow_ctx_st t len
let bn_mod_ctx #t len bn_mod_slow_precomp k a res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"Prims.pow2",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post",
"Lib.Buffer.as_seq",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n"
] | [] | false | false | false | false | true | let bn_mod_exp_ctx_st (t: limb_t) (len: BN.meta_len t) =
|
k: MA.pbn_mont_ctx t ->
a: lbignum t len ->
bBits: size_t ->
b: lbignum t (blocks0 bBits (size (bits t))) ->
res: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ bn_v h a < MA.bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\ live h a /\ live h b /\ live h res /\ disjoint res a /\
disjoint res b /\ B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\
SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n)
(as_seq h0 a)
(v bBits)
(as_seq h0 b)
(as_seq h1 res)) | false |
|
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.le_quad32_to_bytes_sel | val le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) :
Lemma(let Mkfour q0 q1 q2 q3 = q in
(i < 4 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q0) (i % 4)) /\
(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q1) (i % 4)) /\
(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q2) (i % 4)) /\
(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q3) (i % 4))) | val le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) :
Lemma(let Mkfour q0 q1 q2 q3 = q in
(i < 4 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q0) (i % 4)) /\
(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q1) (i % 4)) /\
(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q2) (i % 4)) /\
(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i = four_select (nat_to_four 8 q3) (i % 4))) | let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 104,
"end_line": 233,
"start_col": 0,
"start_line": 151
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 2,
"max_ifuel": 0,
"no_plugins": false,
"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": "native",
"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",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3",
"smt.arith.nl=true"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> i: Prims.nat{i < 16}
-> FStar.Pervasives.Lemma
(ensures
(let _ = q in
(let { lo0 = q0 ; lo1 = q1 ; hi2 = q2 ; hi3 = q3 } = _ in
(i < 4 ==>
FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i =
Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q0) (i % 4)) /\
(4 <= i /\ i < 8 ==>
FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i =
Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q1) (i % 4)) /\
(8 <= i /\ i < 12 ==>
FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i =
Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q2) (i % 4)) /\
(12 <= i /\ i < 16 ==>
FStar.Seq.Base.index (Vale.Def.Types_s.le_quad32_to_bytes q) i =
Vale.Def.Words.Four_s.four_select (Vale.Def.Words.Four_s.nat_to_four 8 q3) (i % 4)))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Prims._assert",
"Prims.l_imp",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"FStar.Seq.Base.index",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.le_quad32_to_bytes",
"Vale.Def.Words.Four_s.four_select",
"Vale.Def.Words.Four_s.nat_to_four",
"Prims.op_Modulus",
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.op_Equality",
"FStar.Seq.Base.init",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Seq_s.four_to_seq_LE",
"Prims.op_Division",
"FStar.Stubs.Tactics.V1.Builtins.dump",
"FStar.Stubs.Tactics.V1.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.primops",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Prims.l_True",
"Prims.int"
] | [] | false | false | true | false | false | let le_quad32_to_bytes_sel (q: quad32) (i: nat{i < 16}) =
| reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm [delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert (i < 4 ==>
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i ==
four_select (nat_to_four 8 q0) i);
assert (4 <= i /\ i < 8 ==>
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i ==
four_select (nat_to_four 8 q1) (i % 4));
assert (8 <= i /\ i < 12 ==>
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i ==
four_select (nat_to_four 8 q2) (i % 4));
assert (12 <= i /\ i < 16 ==>
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i ==
four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==>
index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)))
i))
(fun () ->
norm [
primops;
delta_only [
`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map;
`%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE
]
];
dump " after norm2");
assert (i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert (4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4)
);
assert (8 <= i /\ i < 12 ==>
index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert (12 <= i /\ i < 16 ==>
index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) | false |
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.qbuf_qual | val qbuf_qual (c: qbuf 'a) : qual | val qbuf_qual (c: qbuf 'a) : qual | let qbuf_qual (c:qbuf 'a) : qual = dfst c | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 41,
"end_line": 78,
"start_col": 0,
"start_line": 78
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.qbuf 'a -> LowStar.ConstBuffer.qual | Prims.Tot | [
"total"
] | [] | [
"LowStar.ConstBuffer.qbuf",
"FStar.Pervasives.dfst",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qbuf_cases"
] | [] | false | false | false | true | false | let qbuf_qual (c: qbuf 'a) : qual =
| dfst c | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.mk_bn_mod_exp_safe | val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len | val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len | let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 193,
"start_col": 0,
"start_line": 183
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Bignum.meta_len t ->
exp_check: Hacl.Bignum.Exponentiation.bn_check_mod_exp_st t len ->
bn_mod_exp: Hacl.Bignum.Exponentiation.bn_mod_exp_st t len
-> Hacl.Bignum.SafeAPI.bn_mod_exp_safe_st t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Exponentiation.bn_check_mod_exp_st",
"Hacl.Bignum.Exponentiation.bn_mod_exp_st",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb",
"Prims.bool",
"Prims.unit",
"Hacl.Spec.Bignum.Lib.bn_low_bound_bits_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.memset",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.range",
"Prims.op_Multiply",
"Lib.IntTypes.mk_int",
"Hacl.Spec.Bignum.Base.unsafe_size_from_limb",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Subtraction",
"Prims.pow2",
"Hacl.Bignum.Lib.bn_get_top_index",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
| let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m
then
(SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res)
else memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | false |
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.qbuf | val qbuf : a: Type0 -> Type0 | let qbuf a = (q:qual & qbuf_cases q a) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 75,
"start_col": 0,
"start_line": 75
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.dtuple2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qbuf_cases"
] | [] | false | false | false | true | true | let qbuf a =
| (q: qual & qbuf_cases q a) | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.qual_of | val qual_of (#a: _) (c: const_buffer a) : Tot qual | val qual_of (#a: _) (c: const_buffer a) : Tot qual | let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 99,
"start_col": 0,
"start_line": 97
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.const_buffer a -> LowStar.ConstBuffer.qual | Prims.Tot | [
"total"
] | [] | [
"LowStar.ConstBuffer.const_buffer",
"FStar.Pervasives.dfst",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qbuf_cases",
"LowStar.ConstBuffer.as_qbuf"
] | [] | false | false | false | true | false | let qual_of (#a: _) (c: const_buffer a) : Tot qual =
| dfst (as_qbuf c) | false |
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.qbuf_pre | val qbuf_pre : c: LowStar.ConstBuffer.qbuf 'a -> FStar.Preorder.preorder (FStar.Seq.Base.seq 'a) | let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 81,
"start_col": 0,
"start_line": 81
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.qbuf 'a -> FStar.Preorder.preorder (FStar.Seq.Base.seq 'a) | Prims.Tot | [
"total"
] | [] | [
"LowStar.ConstBuffer.qbuf",
"LowStar.ConstBuffer.q_preorder",
"LowStar.ConstBuffer.qbuf_qual",
"FStar.Preorder.preorder",
"FStar.Seq.Base.seq"
] | [] | false | false | false | true | false | let qbuf_pre (c: qbuf 'a) =
| q_preorder (qbuf_qual c) 'a | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.live | val live : h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a -> Type0 | let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 107,
"start_col": 0,
"start_line": 107
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowStar.ConstBuffer.const_buffer",
"LowStar.Monotonic.Buffer.live",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf"
] | [] | false | false | false | true | true | let live (h: HS.mem) (c: const_buffer 'a) =
| B.live h (as_mbuf c) | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.qbuf_cases | val qbuf_cases : q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot Type0 | let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 61,
"start_col": 0,
"start_line": 58
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.ConstBuffer.qual",
"LowStar.Buffer.buffer",
"LowStar.ImmutableBuffer.ibuffer"
] | [] | false | false | false | false | true | let qbuf_cases (q: qual) (a: Type) =
| match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.length | val length : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.nat | let length (c:const_buffer 'a) = B.length (as_mbuf c) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 108,
"start_col": 0,
"start_line": 108
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.nat | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.ConstBuffer.const_buffer",
"LowStar.Monotonic.Buffer.length",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Prims.nat"
] | [] | false | false | false | false | false | let length (c: const_buffer 'a) =
| B.length (as_mbuf c) | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.loc_buffer | val loc_buffer : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc | let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 69,
"end_line": 109,
"start_col": 0,
"start_line": 109
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.ConstBuffer.const_buffer",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let loc_buffer (c: const_buffer 'a) =
| B.loc_buffer (as_mbuf c) | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.loc_addr_of_buffer | val loc_addr_of_buffer : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc | let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 77,
"end_line": 110,
"start_col": 0,
"start_line": 110
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
let length (c:const_buffer 'a) = B.length (as_mbuf c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.ConstBuffer.const_buffer",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let loc_addr_of_buffer (c: const_buffer 'a) =
| B.loc_addr_of_buffer (as_mbuf c) | false |
|
LowParse.Low.Base.fst | LowParse.Low.Base.list_flatten_map | val list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0})
(f: (t1 -> Tot (list t2)))
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1': U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2:
U32.t
{ valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32 })
(f':
(pos1_: U32.t -> pos2_: U32.t
-> HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\
(let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y
)))))
: HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\
(let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) | val list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0})
(f: (t1 -> Tot (list t2)))
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1': U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2:
U32.t
{ valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32 })
(f':
(pos1_: U32.t -> pos2_: U32.t
-> HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\
(let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y
)))))
: HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\
(let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) | let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1879,
"start_col": 0,
"start_line": 1747
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 256,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
j1: LowParse.Low.Base.jumper p1 ->
s2:
LowParse.Spec.Base.serializer p2
{ Mkparser_kind'?.parser_kind_subkind k2 ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_low k2 > 0 } ->
f: (_: t1 -> Prims.list t2) ->
h0: FStar.Monotonic.HyperStack.mem ->
sl1: LowParse.Slice.slice rrel1 rel1 ->
pos1: FStar.UInt32.t ->
pos1': FStar.UInt32.t ->
sl2: LowParse.Slice.slice rrel2 rel2 ->
pos2:
FStar.UInt32.t
{ LowParse.Low.Base.Spec.valid_list p1 h0 sl1 pos1 pos1' /\
FStar.UInt32.v pos1 <= FStar.UInt32.v pos1' /\
FStar.UInt32.v pos1' <= FStar.UInt32.v (Mkslice?.len sl1) /\
FStar.UInt32.v pos2 <= FStar.UInt32.v (Mkslice?.len sl2) /\
LowStar.Monotonic.Buffer.loc_disjoint (LowParse.Slice.loc_slice_from_to sl1 pos1 pos1')
(LowParse.Slice.loc_slice_from sl2 pos2) /\
FStar.UInt32.v (Mkslice?.len sl2) < FStar.UInt32.v LowParse.Low.ErrorCode.max_uint32 } ->
f': (pos1_: FStar.UInt32.t -> pos2_: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t)
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Spec.Base.serializer",
"Prims.l_and",
"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",
"Prims.b2t",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.list",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.valid_list",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Slice.loc_slice_from",
"Prims.op_LessThan",
"LowParse.Low.ErrorCode.max_uint32",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Low.Base.Spec.valid",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Slice.live_slice",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.op_Equality",
"LowParse.Low.Base.Spec.serialized_list_length",
"Prims.bool",
"LowParse.Low.Base.Spec.contents_list",
"Prims.logical",
"LowParse.Low.Base.Spec.contents",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"LowParse.Low.Base.list_fold_left_gen",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_region_only",
"FStar.Monotonic.HyperStack.get_tip",
"LowStar.Monotonic.Buffer.live",
"FStar.List.Tot.Base.append",
"FStar.List.Tot.Base.flatten",
"FStar.List.Tot.Base.map",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowParse.Low.Base.Spec.valid_list_append",
"LowParse.Low.Base.Spec.valid_list_nil",
"LowParse.Low.Base.Spec.valid_list_snoc",
"LowParse.Low.Base.Spec.list_flatten_map_append",
"Prims.Cons",
"Prims.Nil",
"FStar.List.Tot.Properties.append_assoc",
"LowParse.Low.Base.writable_modifies",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.upd",
"LowParse.Low.Base.Spec.valid_list_serialized_list_length",
"LowParse.Low.Base.Spec.serialized_list_length_append",
"LowParse.Low.Base.Spec.valid_list_cons",
"Prims.op_Negation",
"LowParse.Low.Base.Spec.valid_pos_frame_strong",
"LowParse.Low.Base.writable_weaken",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.uint_to_t",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0})
(f: (t1 -> Tot (list t2)))
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1': U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2:
U32.t
{ valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32 })
(f':
(pos1_: U32.t -> pos2_: U32.t
-> HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\
(let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\ contents_list p2 h' sl2 pos2_ res == y
)))))
: HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\
(let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) =
| let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits =
list_fold_left_gen p1 j1 sl1 pos1 pos1' h2
(Ghost.hide ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2)))
(fun h ll lr _ ->
B.modifies ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2)
)
h2
h /\ B.live h bpos2_ /\
(let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in ((B.loc_region_only true (HS.get_tip h1))
`B.loc_union`
(loc_slice_from sl2 pos2))
h2
h';
B.loc_unused_in_not_unused_in_disjoint h2)
(fun h ->
B.modifies ((B.loc_region_only true (HS.get_tip h1)) `B.loc_union` (loc_slice_from sl2 pos2)
)
h2
h /\
U32.v pos2 +
serialized_list_length s2
(List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) >
U32.v sl2.len)
(fun h h' ->
B.modifies_only_not_unused_in ((B.loc_region_only true (HS.get_tip h1))
`B.loc_union`
(loc_slice_from sl2 pos2))
h2
h';
B.loc_unused_in_not_unused_in_disjoint h2)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits
then
(B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base
(U32.v pos2)
(U32.v sl2.len)
h
(B.loc_region_only true (HS.get_tip h1))
h';
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l)
[contents p1 h0 sl1 pos1l]
(contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f
(contents_list p1 h0 sl1 pos1 pos1l)
[contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res)
else
(let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1';
valid_list_append p1 h0 sl1 pos1 pos1l pos1';
list_flatten_map_append f
(contents_list p1 h0 sl1 pos1 pos1l)
(contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2
(L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l)))
(L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2
(f (contents p1 h0 sl1 pos1l))
(L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_);
fits)
in
let res = if fits then B.index bpos2_ 0ul else max_uint32 in
HST.pop_frame ();
res | false |
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.as_seq | val as_seq : h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a
-> Prims.GTot (FStar.Seq.Base.seq 'a) | let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 67,
"end_line": 111,
"start_col": 0,
"start_line": 111
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
let length (c:const_buffer 'a) = B.length (as_mbuf c)
let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> c: LowStar.ConstBuffer.const_buffer 'a
-> Prims.GTot (FStar.Seq.Base.seq 'a) | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowStar.ConstBuffer.const_buffer",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"FStar.Seq.Base.seq"
] | [] | false | false | false | false | false | let as_seq (h: HS.mem) (c: const_buffer 'a) =
| B.as_seq h (as_mbuf c) | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.q_preorder | val q_preorder : q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot (LowStar.Monotonic.Buffer.srel a) | let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 70,
"start_col": 0,
"start_line": 67
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: LowStar.ConstBuffer.qual -> a: Type0 -> Prims.GTot (LowStar.Monotonic.Buffer.srel a) | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.ConstBuffer.qual",
"LowStar.Buffer.trivial_preorder",
"LowStar.ImmutableBuffer.immutable_preorder",
"LowStar.Monotonic.Buffer.srel"
] | [] | false | false | false | false | false | let q_preorder (q: qual) (a: Type) =
| match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.g_is_null | val g_is_null : c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.bool | let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 68,
"end_line": 112,
"start_col": 0,
"start_line": 112
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
let length (c:const_buffer 'a) = B.length (as_mbuf c)
let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c)
let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.const_buffer 'a -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.ConstBuffer.const_buffer",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.as_qbuf",
"LowStar.ConstBuffer.as_mbuf",
"Prims.bool"
] | [] | false | false | false | false | false | let g_is_null (c: const_buffer 'a) =
| B.g_is_null (as_mbuf c) | false |
|
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.const_sub_buffer | val const_sub_buffer : i: FStar.UInt32.t ->
len: FStar.UInt32.t ->
csub: LowStar.ConstBuffer.const_buffer 'a ->
c: LowStar.ConstBuffer.const_buffer 'a
-> Prims.logical | let const_sub_buffer (i:U32.t) (len:U32.t) (csub c:const_buffer 'a) =
let qc = as_qbuf c in
let qcsub = as_qbuf csub in
U32.v i + U32.v len <= length c /\
csub == gsub c i len | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 183,
"start_col": 0,
"start_line": 179
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
let length (c:const_buffer 'a) = B.length (as_mbuf c)
let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c)
let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c)
let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c)
let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c)
(*** CONSTRUCTORS **)
/// `of_buffer`: A constructors for const buffers from mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_buffer (b:B.buffer 'a)
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == MUTABLE /\
qbuf_mbuf c == b)
/// `of_ibuffer`: A constructors for const buffers from mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_ibuffer (b:I.ibuffer 'a)
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == IMMUTABLE /\
qbuf_mbuf c == b)
/// `of_qbuf`: A constructors for const buffers from either mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_qbuf (#q:qual) (b:B.mbuffer 'a (q_preorder q 'a) (q_preorder q 'a))
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == q /\
qbuf_mbuf c == b)
/// null constant buffer
let null 'a : const_buffer 'a = of_buffer B.null
(*** OPERATIONS ON CONST POINTERS **)
/// Is the buffer the null pointer?
val is_null (c:const_buffer 'a)
: Stack bool (requires (fun h -> live h c))
(ensures (fun h y h' -> h == h' /\ y == g_is_null c))
/// `index c i`: Very similar to the spec for `Buffer.index`
val index (c:const_buffer 'a) (i:U32.t)
: Stack 'a
(requires fun h ->
live h c /\
U32.v i < length c)
(ensures fun h0 y h1 ->
h0 == h1 /\
y == Seq.index (as_seq h0 c) (U32.v i))
/// Specification of sub
let gsub (c:const_buffer 'a) (i:U32.t) (len:U32.t{U32.v i + U32.v len <= length c})
: GTot (const_buffer 'a)
= let qc = as_qbuf c in
of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: FStar.UInt32.t ->
len: FStar.UInt32.t ->
csub: LowStar.ConstBuffer.const_buffer 'a ->
c: LowStar.ConstBuffer.const_buffer 'a
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"LowStar.ConstBuffer.const_buffer",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowStar.ConstBuffer.length",
"Prims.eq2",
"LowStar.ConstBuffer.gsub",
"LowStar.ConstBuffer.qbuf",
"LowStar.ConstBuffer.as_qbuf",
"Prims.logical"
] | [] | false | false | false | true | true | let const_sub_buffer (i len: U32.t) (csub c: const_buffer 'a) =
| let qc = as_qbuf c in
let qcsub = as_qbuf csub in
U32.v i + U32.v len <= length c /\ csub == gsub c i len | false |
|
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_mod_n_8_lower1 | val lemma_mod_n_8_lower1 (q: quad32) (n: nat)
: Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) | val lemma_mod_n_8_lower1 (q: quad32) (n: nat)
: Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) | let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 293,
"start_col": 0,
"start_line": 281
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires n <= 4)
(ensures Vale.Arch.Types.lo64 q % Prims.pow2 (8 * n) == Mkfour?.lo0 q % Prims.pow2 (8 * n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.logical",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Vale.Arch.Types.lo64_def",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Arch.Types.lo64_reveal",
"Prims.squash",
"Vale.Arch.Types.lo64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_mod_n_8_lower1 (q: quad32) (n: nat)
: Lemma (requires n <= 4) (ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n)) =
| lo64_reveal ();
let Mkfour _ _ _ _ = q in
let f (n: nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
() | false |
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.qbuf_mbuf | val qbuf_mbuf (c: qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) | val qbuf_mbuf (c: qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) | let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 84,
"start_col": 0,
"start_line": 84
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: LowStar.ConstBuffer.qbuf 'a
-> LowStar.Monotonic.Buffer.mbuffer 'a
(LowStar.ConstBuffer.qbuf_pre c)
(LowStar.ConstBuffer.qbuf_pre c) | Prims.Tot | [
"total"
] | [] | [
"LowStar.ConstBuffer.qbuf",
"FStar.Pervasives.dsnd",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qbuf_cases",
"LowStar.Monotonic.Buffer.mbuffer",
"LowStar.ConstBuffer.qbuf_pre"
] | [] | false | false | false | false | false | let qbuf_mbuf (c: qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) =
| dsnd c | false |
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.gsub | val gsub (c: const_buffer 'a) (i: U32.t) (len: U32.t{U32.v i + U32.v len <= length c})
: GTot (const_buffer 'a) | val gsub (c: const_buffer 'a) (i: U32.t) (len: U32.t{U32.v i + U32.v len <= length c})
: GTot (const_buffer 'a) | let gsub (c:const_buffer 'a) (i:U32.t) (len:U32.t{U32.v i + U32.v len <= length c})
: GTot (const_buffer 'a)
= let qc = as_qbuf c in
of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len) | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 176,
"start_col": 0,
"start_line": 173
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
let length (c:const_buffer 'a) = B.length (as_mbuf c)
let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c)
let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c)
let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c)
let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c)
(*** CONSTRUCTORS **)
/// `of_buffer`: A constructors for const buffers from mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_buffer (b:B.buffer 'a)
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == MUTABLE /\
qbuf_mbuf c == b)
/// `of_ibuffer`: A constructors for const buffers from mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_ibuffer (b:I.ibuffer 'a)
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == IMMUTABLE /\
qbuf_mbuf c == b)
/// `of_qbuf`: A constructors for const buffers from either mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_qbuf (#q:qual) (b:B.mbuffer 'a (q_preorder q 'a) (q_preorder q 'a))
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == q /\
qbuf_mbuf c == b)
/// null constant buffer
let null 'a : const_buffer 'a = of_buffer B.null
(*** OPERATIONS ON CONST POINTERS **)
/// Is the buffer the null pointer?
val is_null (c:const_buffer 'a)
: Stack bool (requires (fun h -> live h c))
(ensures (fun h y h' -> h == h' /\ y == g_is_null c))
/// `index c i`: Very similar to the spec for `Buffer.index`
val index (c:const_buffer 'a) (i:U32.t)
: Stack 'a
(requires fun h ->
live h c /\
U32.v i < length c)
(ensures fun h0 y h1 ->
h0 == h1 /\
y == Seq.index (as_seq h0 c) (U32.v i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c: LowStar.ConstBuffer.const_buffer 'a ->
i: FStar.UInt32.t ->
len: FStar.UInt32.t{FStar.UInt32.v i + FStar.UInt32.v len <= LowStar.ConstBuffer.length c}
-> Prims.GTot (LowStar.ConstBuffer.const_buffer 'a) | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.ConstBuffer.const_buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowStar.ConstBuffer.length",
"LowStar.ConstBuffer.of_qbuf",
"LowStar.ConstBuffer.qbuf_qual",
"LowStar.Monotonic.Buffer.mgsub",
"LowStar.ConstBuffer.qbuf_pre",
"LowStar.ConstBuffer.qbuf_mbuf",
"LowStar.ConstBuffer.qbuf",
"LowStar.ConstBuffer.as_qbuf"
] | [] | false | false | false | false | false | let gsub (c: const_buffer 'a) (i: U32.t) (len: U32.t{U32.v i + U32.v len <= length c})
: GTot (const_buffer 'a) =
| let qc = as_qbuf c in
of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len) | false |
LowStar.ConstBuffer.fsti | LowStar.ConstBuffer.test | val test (x: B.buffer U32.t) (y: I.ibuffer U32.t)
: Stack U32.t
(requires
fun h ->
B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\
B.get h y 1 == 2ul /\ B.disjoint x y)
(ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul) | val test (x: B.buffer U32.t) (y: I.ibuffer U32.t)
: Stack U32.t
(requires
fun h ->
B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\
B.get h y 1 == 2ul /\ B.disjoint x y)
(ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul) | let test (x:B.buffer U32.t) (y:I.ibuffer U32.t)
: Stack U32.t
(requires fun h ->
B.live h x /\
B.live h y /\
B.length x > 0 /\
B.length y > 2 /\
B.get h y 0 == 1ul /\
B.get h y 1 == 2ul /\
B.disjoint x y)
(ensures fun h0 a h1 ->
B.modifies (B.loc_buffer x) h0 h1 /\
a == 4ul)
= let c1 = of_buffer x in
let c2 = of_ibuffer y in
B.upd x 0ul 1ul;
let a = index c1 0ul in
assert (a == 1ul);
let a' = index c2 0ul in
assert (a' == 1ul);
let c3 = sub c2 1ul 1ul in
let a'' = index c3 0ul in
assert (a'' == 2ul);
U32.(a +^ a' +^ a'') | {
"file_name": "ulib/LowStar.ConstBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 298,
"start_col": 0,
"start_line": 275
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module LowStar.ConstBuffer
(* This module provides a model of const pointers in C.
A well-typed client guarantees that it will not mutate memory
through a const pointer. But it cannot rely on the context not
mutating the same memory.
As such, we model const pointers as a finite disjunction of
{mutable, immutable}-pointers, forcing code to guarantee the
strongest condition of the two (immutability) and to rely only on
the weakest (i.e., mutability).
The main type of this module is `const_buffer t`. It is extracted
by KaRaMeL to `const t*`.
*)
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
open FStar.HyperStack.ST
module I = LowStar.ImmutableBuffer
module B = LowStar.Buffer
(*** A model for const pointers **)
/// We start by defining the finite disjunction of mutable and
/// immutable buffers.
///
/// NB: THIS IS FOR SPECIFICATIONAL PURPOSES ONLY
/// The concrete type `const_buffer` is defined later
/// `qual`: mutability qualifier
[@@erasable]
noeq
type qual =
| MUTABLE
| IMMUTABLE
/// `qbuf_cases q a`: disjunction of mutable and immutable pointers
let qbuf_cases (q:qual) (a:Type) =
match q with
| MUTABLE -> B.buffer a
| IMMUTABLE -> I.ibuffer a
/// `q_preorder q a`: As we'll see shortly, it is convenient to also
/// define a disjunction of the preorder indices on a qualified
/// buffer
inline_for_extraction
let q_preorder (q:qual) (a:Type) =
match q with
| MUTABLE -> B.trivial_preorder a
| IMMUTABLE -> I.immutable_preorder a
/// `qbuf a`: This type is used for specificational purposes only. It
/// is buffer whose mutability qualifier is existentially bound, via
/// a dependent pair
let qbuf a = (q:qual & qbuf_cases q a)
/// `qbuf_qual c`: projecting the mutability qualifier of a `qbuf`
let qbuf_qual (c:qbuf 'a) : qual = dfst c
/// `qbuf_pre c`: case-dependent preorders for a qbuf
let qbuf_pre (c:qbuf 'a) = q_preorder (qbuf_qual c) 'a
/// `qbuf_mbuf c`: turning a qbuf into a regular monotonic buffer
let qbuf_mbuf (c:qbuf 'a) : B.mbuffer 'a (qbuf_pre c) (qbuf_pre c) = dsnd c
(*** CONCRETE CONST POINTERS **)
/// `const_buffer`:
/// An abstract type of a read-only pointer to an array of `a`
val const_buffer (a:Type u#0) : Type u#0
/// `as_qbuf`: For specificational purposes, a const_buffer can be
/// seen as an existentially quantified qbuf
val as_qbuf (c:const_buffer 'a) : Tot (qbuf 'a)
/// `qual_of`:
let qual_of (#a:_) (c:const_buffer a)
: Tot qual
= dfst (as_qbuf c)
/// `as_mbuf`: A convenience function to turn a const_buffer into a
/// regular mbuffer, for spec purposes
let as_mbuf (c:const_buffer 'a) : GTot _ = qbuf_mbuf (as_qbuf c)
/// We now give several convenience functions that lift common
/// notions on buffers to const_buffer, via the `as_mbuf` coercion
let live (h:HS.mem) (c:const_buffer 'a) = B.live h (as_mbuf c)
let length (c:const_buffer 'a) = B.length (as_mbuf c)
let loc_buffer (c:const_buffer 'a) = B.loc_buffer (as_mbuf c)
let loc_addr_of_buffer (c:const_buffer 'a) = B.loc_addr_of_buffer (as_mbuf c)
let as_seq (h:HS.mem) (c:const_buffer 'a) = B.as_seq h (as_mbuf c)
let g_is_null (c:const_buffer 'a) = B.g_is_null (as_mbuf c)
(*** CONSTRUCTORS **)
/// `of_buffer`: A constructors for const buffers from mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_buffer (b:B.buffer 'a)
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == MUTABLE /\
qbuf_mbuf c == b)
/// `of_ibuffer`: A constructors for const buffers from mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_ibuffer (b:I.ibuffer 'a)
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == IMMUTABLE /\
qbuf_mbuf c == b)
/// `of_qbuf`: A constructors for const buffers from either mutable and
/// immutable buffers. It is fully specified in terms of the
/// `qbuf/mbuf` model
val of_qbuf (#q:qual) (b:B.mbuffer 'a (q_preorder q 'a) (q_preorder q 'a))
: Pure (const_buffer 'a)
(requires True)
(ensures fun c ->
let c = as_qbuf c in
qbuf_qual c == q /\
qbuf_mbuf c == b)
/// null constant buffer
let null 'a : const_buffer 'a = of_buffer B.null
(*** OPERATIONS ON CONST POINTERS **)
/// Is the buffer the null pointer?
val is_null (c:const_buffer 'a)
: Stack bool (requires (fun h -> live h c))
(ensures (fun h y h' -> h == h' /\ y == g_is_null c))
/// `index c i`: Very similar to the spec for `Buffer.index`
val index (c:const_buffer 'a) (i:U32.t)
: Stack 'a
(requires fun h ->
live h c /\
U32.v i < length c)
(ensures fun h0 y h1 ->
h0 == h1 /\
y == Seq.index (as_seq h0 c) (U32.v i))
/// Specification of sub
let gsub (c:const_buffer 'a) (i:U32.t) (len:U32.t{U32.v i + U32.v len <= length c})
: GTot (const_buffer 'a)
= let qc = as_qbuf c in
of_qbuf (B.mgsub (qbuf_pre qc) (qbuf_mbuf qc) i len)
/// Relational specification of sub
let const_sub_buffer (i:U32.t) (len:U32.t) (csub c:const_buffer 'a) =
let qc = as_qbuf c in
let qcsub = as_qbuf csub in
U32.v i + U32.v len <= length c /\
csub == gsub c i len
/// `sub`: A sub-buffer of a const buffer points to a given
/// within-bounds offset of its head
val sub (#a:_) (c:const_buffer a) (i:U32.t) (len:Ghost.erased (U32.t))
: Stack (const_buffer a)
(requires fun h ->
live h c /\
U32.v i + U32.v len <= length c)
(ensures fun h0 c' h1 ->
let qc = as_qbuf c in
let qc' = as_qbuf c' in
h0 == h1 /\
c' `const_sub_buffer i len` c)
/// Discussion between NS and JP (20191119)
///
/// Why is it safe to generate C code that casts away the const qualifier with the
/// cast operations below? Looking at the C11 standard, 6.7.3 alinea 6:
///
/// > If an attempt is made to modify an object defined with a const-qualified type
/// > through useof an lvalue with non-const-qualified type, the behavior is
/// > undefined.
///
/// So, dangerous things happen in situations where the original object is *created*
/// with a const qualifier (the object's _identity_ is const).
///
/// ```
/// #include <stdio.h>
/// #include <stdlib.h>
///
/// extern void f(const int *x);
///
/// int main() {
/// const int x = 0;
/// f(&x); // f promises not to modify x
/// printf("%d\n", x); // prints 0 at -O3 but 1 at -O0
/// return 0;
/// }
/// ```
///
/// with:
///
/// ```
/// void f(const int *x) {
/// int *y = (int *)x;
/// *y = 1;
/// }
/// ```
///
/// In Low*, however, we never create objects that are marked const from the start.
/// This is for historical reasons; in particular, immutable buffers are not marked
/// const (they certainly could be).
///
/// So, the casts seem to be safe? Also, the difference in behavior noted above
/// does not happen if x is defined as
///
/// ```
/// const int *x = calloc(1, sizeof *x);
/// ```
///
/// Finally, the compiler, if the const qualifier is stripped from x, could still
/// potentially rely on an argument of freshness (pointer provenance?) to deduce
/// that &x is the sole pointer to x and that therefore the value of x should remain
/// the same. This does not seem to be happening.
/// `cast`: It is possible to cast away the const qualifier recovering
/// a mutable or immutable pointer, in case the context can prove
/// that `qbuf_qual c` is MUTABLE or IMMUTABLE, respectively
val cast (c:const_buffer 'a)
: Pure (B.mbuffer 'a (qbuf_pre (as_qbuf c)) (qbuf_pre (as_qbuf c)))
(requires True)
(ensures fun x ->
x == as_mbuf c)
val to_buffer (c:const_buffer 'a)
: Pure (B.buffer 'a)
(requires (
let c = as_qbuf c in
qbuf_qual c == MUTABLE))
(ensures fun x ->
x == as_mbuf c)
val to_ibuffer (c:const_buffer 'a)
: Pure (I.ibuffer 'a)
(requires (
let c = as_qbuf c in
qbuf_qual c == IMMUTABLE))
(ensures fun x ->
x == as_mbuf c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.ImmutableBuffer.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.ConstBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.ImmutableBuffer",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"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": 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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: LowStar.Buffer.buffer FStar.UInt32.t -> y: LowStar.ImmutableBuffer.ibuffer FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowStar.Buffer.buffer",
"FStar.UInt32.t",
"LowStar.ImmutableBuffer.ibuffer",
"FStar.UInt32.op_Plus_Hat",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"FStar.UInt32.__uint_to_t",
"LowStar.ConstBuffer.index",
"LowStar.ConstBuffer.const_buffer",
"LowStar.ConstBuffer.sub",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.upd",
"LowStar.Buffer.trivial_preorder",
"LowStar.ConstBuffer.of_ibuffer",
"LowStar.ConstBuffer.of_buffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.ImmutableBuffer.immutable_preorder",
"Prims.b2t",
"Prims.op_GreaterThan",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.get",
"LowStar.Monotonic.Buffer.disjoint",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer"
] | [] | false | true | false | false | false | let test (x: B.buffer U32.t) (y: I.ibuffer U32.t)
: Stack U32.t
(requires
fun h ->
B.live h x /\ B.live h y /\ B.length x > 0 /\ B.length y > 2 /\ B.get h y 0 == 1ul /\
B.get h y 1 == 2ul /\ B.disjoint x y)
(ensures fun h0 a h1 -> B.modifies (B.loc_buffer x) h0 h1 /\ a == 4ul) =
| let c1 = of_buffer x in
let c2 = of_ibuffer y in
B.upd x 0ul 1ul;
let a = index c1 0ul in
assert (a == 1ul);
let a' = index c2 0ul in
assert (a' == 1ul);
let c3 = sub c2 1ul 1ul in
let a'' = index c3 0ul in
assert (a'' == 2ul);
let open U32 in a +^ a' +^ a'' | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8 | val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a | val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a | let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 93,
"start_col": 0,
"start_line": 81
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.sha2_alg ->
k_t: Hacl.Spec.SHA2.Vec.word a ->
ws_t: Hacl.Spec.SHA2.Vec.word a ->
hash: Hacl.Spec.SHA2.Vec.words_state' a
-> Hacl.Spec.SHA2.Vec.words_state' a | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.words_state'",
"Lib.Sequence.create8",
"Lib.IntTypes.op_Plus_Dot",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Hacl.Spec.SHA2._Sigma0",
"Hacl.Spec.SHA2._Maj",
"Hacl.Spec.SHA2._Sigma1",
"Hacl.Spec.SHA2._Ch",
"FStar.Seq.Base.index"
] | [] | false | false | false | false | false | let shuffle_core_pre_create8 a k_t ws_t hash =
| let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.seq_of_list_is_create8 | val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) | val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) | let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 77,
"start_col": 0,
"start_line": 67
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x0: a -> x1: a -> x2: a -> x3: a -> x4: a -> x5: a -> x6: a -> x7: a
-> FStar.Pervasives.Lemma
(ensures
Lib.Sequence.create8 x0 x1 x2 x3 x4 x5 x6 x7 ==
FStar.Seq.Base.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.Sequence.eq_intro",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Pervasives.assert_norm",
"Lib.Sequence.lseq",
"Lib.Sequence.create8",
"Prims._assert",
"Prims.int",
"Lib.Sequence.length",
"FStar.List.Tot.Base.length",
"Prims.Cons",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.length",
"FStar.Seq.Base.seq_of_list"
] | [] | false | false | true | false | false | let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
| let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i: nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i)
in
Classical.forall_intro aux;
eq_intro rp lp | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8_lemma | val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) | val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) | let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 110,
"start_col": 0,
"start_line": 98
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.sha2_alg ->
k_t: Hacl.Spec.SHA2.Vec.word a ->
ws_t: Hacl.Spec.SHA2.Vec.word a ->
hash: Hacl.Spec.SHA2.Vec.words_state' a
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.SHA2.shuffle_core_pre a k_t ws_t hash ==
Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8 a k_t ws_t hash) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Equiv.seq_of_list_is_create8",
"Lib.IntTypes.int_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Plus_Dot",
"Hacl.Spec.SHA2._Sigma0",
"Hacl.Spec.SHA2._Maj",
"Hacl.Spec.SHA2._Sigma1",
"Hacl.Spec.SHA2._Ch",
"FStar.Seq.Base.index",
"Prims.unit"
] | [] | true | false | true | false | false | let shuffle_core_pre_create8_lemma a k_t ws_t hash =
| let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm256_encrypt_opt | val gcm256_encrypt_opt : Vale.Interop.Base.normal (
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256_t s iv) | let gcm256_encrypt_opt //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_gcm256_t s)
= as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> (iv:Ghost.erased supported_iv_LE) -> lowstar_gcm256_t s iv) (fun (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) -> lowstar_gcm256 s iv) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 209,
"end_line": 404,
"start_col": 0,
"start_line": 403
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm256_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm256_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm256_lemma' has the required type *)
noextract
let gcm256_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm256_pre s iv) (gcm256_post s iv)) (gcm256_lemma' s iv)
noextract
let code_gcm256 = GC.va_code_Gcm_blocks_stdcall IA.win AES_256
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm256_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm256
dom
[]
_
_
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm256 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm256_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm256
dom
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win))
[@ (CCConv "stdcall") ]
let gcm128_encrypt_opt //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_gcm128_t s)
= as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> (iv:Ghost.erased supported_iv_LE) -> lowstar_gcm128_t s iv) (fun (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) -> lowstar_gcm128 s iv) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Interop.Base.normal (
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256_t s iv) | Prims.Tot | [
"total"
] | [] | [
"Vale.Stdcalls.X64.GCMencryptOpt.as_normal_t",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256_t",
"Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256"
] | [] | false | false | false | false | false | let gcm256_encrypt_opt =
| as_normal_t #(s: Ghost.erased (Seq.seq nat32) -> iv: Ghost.erased supported_iv_LE
-> lowstar_gcm256_t s iv)
(fun (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) -> lowstar_gcm256 s iv) | false |
|
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.ws_next_lemma_l | val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) | val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) | let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 184,
"start_col": 0,
"start_line": 184
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.ws_spec_v (Hacl.Spec.SHA2.Vec.ws_next ws)).[ l ] ==
Hacl.Spec.SHA2.ws_next a (Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.ws_next_lemma_loop",
"Prims.unit"
] | [] | true | false | true | false | false | let ws_next_lemma_l #a #m ws l =
| ws_next_lemma_loop #a #m ws l 16 | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma_l | val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) | val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) | let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 250,
"start_col": 0,
"start_line": 248
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Prims.nat{i < Hacl.Spec.SHA2.num_rounds16 a} ->
ws_st: (Hacl.Spec.SHA2.Vec.ws_spec a m * Hacl.Spec.SHA2.Vec.state_spec a m) ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.SHA2.Vec.shuffle_inner_loop i ws_st in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ws1 st1 = _ in
let _ = ws_st in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ws0 st0 = _ in
let _ =
Hacl.Spec.SHA2.shuffle_inner_loop a
i
((Hacl.Spec.SHA2.Vec.ws_spec_v ws0).[ l ],
(Hacl.Spec.SHA2.Vec.state_spec_v st0).[ l ])
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ws st = _ in
(Hacl.Spec.SHA2.Vec.ws_spec_v ws1).[ l ] == ws /\
(Hacl.Spec.SHA2.Vec.state_spec_v st1).[ l ] == st)
<:
Type0)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.num_rounds16",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.ws_next_lemma_l",
"Prims.unit",
"Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma"
] | [] | false | false | true | false | false | let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
| shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_lemma_l | val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) | val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) | let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 294,
"start_col": 0,
"start_line": 293
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.shuffle ws st)).[ l ] ==
Hacl.Spec.SHA2.shuffle a
(Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]
(Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.shuffle_loop_lemma",
"Hacl.Spec.SHA2.num_rounds16",
"Prims.unit"
] | [] | true | false | true | false | false | let shuffle_lemma_l #a #m ws st l =
| shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv._Ch_lemma | val _Ch_lemma (#a #m x y z: _)
: Lemma
(vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m)
(fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
[SMTPat (_Ch x y z)] | val _Ch_lemma (#a #m x y z: _)
: Lemma
(vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m)
(fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
[SMTPat (_Ch x y z)] | let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 94,
"end_line": 27,
"start_col": 0,
"start_line": 21
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) ->
y: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) ->
z: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Ch x y z) ==
Lib.Sequence.createi (Hacl.Spec.SHA2.Vec.lanes a m)
(fun i ->
Hacl.Spec.SHA2._Ch a
(Lib.IntVector.vec_v x).[ i ]
(Lib.IntVector.vec_v y).[ i ]
(Lib.IntVector.vec_v z).[ i ])) [SMTPat (Hacl.Spec.SHA2.Vec._Ch x y z)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._Ch",
"Lib.Sequence.createi",
"Spec.Hash.Definitions.word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2._Ch",
"Lib.Sequence.op_String_Access",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.l_and",
"FStar.Seq.Base.length",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | false | false | true | false | false | let _Ch_lemma #a #m x y z
: Lemma
(vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m)
(fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
[SMTPat (_Ch x y z)] =
| LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.init_lemma_l | val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a) | val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a) | let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 301,
"start_col": 0,
"start_line": 299
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.sha2_alg ->
m: Hacl.Spec.SHA2.Vec.m_spec ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.init a m)).[ l ] == Hacl.Spec.SHA2.init a
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Hacl.Spec.SHA2.Vec.word",
"Spec.Hash.Definitions.state_word_length",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Hacl.Spec.SHA2.Vec.init",
"Hacl.Spec.SHA2.init",
"Prims.unit"
] | [] | true | false | true | false | false | let init_lemma_l a m l =
| eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[ l ] (Spec.init a) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_fold_left_gen | val list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')})
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame:
(h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1))
(ensures (inv h' l1 l2 pos1))))
(post_interrupt: (h: HS.mem -> GTot Type0))
(post_interrupt_frame:
(h: HS.mem -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h))
(ensures (post_interrupt h'))))
(body:
(pos1: U32.t -> pos2: U32.t
-> HST.Stack bool
(requires
(fun h ->
B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\
inv h
(contents_list p h0 sl pos pos1)
(contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos')
pos1))
(ensures
(fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue
then
inv h'
((contents_list p h0 sl pos pos1) `L.append` [contents p h0 sl pos1])
(contents_list p h0 sl pos2 pos')
pos2
else post_interrupt h')))))
: HST.Stack bool
(requires
(fun h ->
h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos))
(ensures
(fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h'))) | val list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')})
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame:
(h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1))
(ensures (inv h' l1 l2 pos1))))
(post_interrupt: (h: HS.mem -> GTot Type0))
(post_interrupt_frame:
(h: HS.mem -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h))
(ensures (post_interrupt h'))))
(body:
(pos1: U32.t -> pos2: U32.t
-> HST.Stack bool
(requires
(fun h ->
B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\
inv h
(contents_list p h0 sl pos pos1)
(contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos')
pos1))
(ensures
(fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue
then
inv h'
((contents_list p h0 sl pos pos1) `L.append` [contents p h0 sl pos1])
(contents_list p h0 sl pos2 pos')
pos2
else post_interrupt h')))))
: HST.Stack bool
(requires
(fun h ->
h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos))
(ensures
(fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h'))) | let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1277,
"start_col": 0,
"start_line": 1150
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 256,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
j: LowParse.Low.Base.jumper p ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t ->
h0: FStar.Monotonic.HyperStack.mem ->
l:
FStar.Ghost.erased LowStar.Monotonic.Buffer.loc
{ LowStar.Monotonic.Buffer.loc_disjoint (FStar.Ghost.reveal l)
(LowParse.Slice.loc_slice_from_to sl pos pos') } ->
inv:
(_: FStar.Monotonic.HyperStack.mem -> _: Prims.list t -> _: Prims.list t -> _: FStar.UInt32.t
-> Prims.GTot Type0) ->
inv_frame:
(
h: FStar.Monotonic.HyperStack.mem ->
l1: Prims.list t ->
l2: Prims.list t ->
pos1: FStar.UInt32.t ->
h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_unused_in h0) h h' /\
inv h l1 l2 pos1) (ensures inv h' l1 l2 pos1)) ->
post_interrupt: (h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Type0) ->
post_interrupt_frame:
(h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_unused_in h0) h h' /\
post_interrupt h) (ensures post_interrupt h')) ->
body: (pos1: FStar.UInt32.t -> pos2: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool)
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"FStar.Ghost.erased",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_disjoint",
"FStar.Ghost.reveal",
"LowParse.Slice.loc_slice_from_to",
"Prims.list",
"Prims.unit",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_unused_in",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.bool",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.valid_pos",
"LowParse.Low.Base.Spec.contents_list",
"Prims.Cons",
"LowParse.Low.Base.Spec.contents",
"FStar.List.Tot.Base.append",
"Prims.logical",
"LowStar.Monotonic.Buffer.loc_regions_unused_in",
"FStar.Set.singleton",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperStack.get_tip",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"LowParse.Low.Base.Spec.valid_list_nil",
"C.Loops.while",
"LowStar.Monotonic.Buffer.upd",
"Prims.op_AmpAmp",
"FStar.UInt32.lt",
"LowParse.Low.Base.Spec.valid_list_snoc",
"LowParse.Low.Base.Spec.valid_pos_frame_strong",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowParse.Low.Base.Spec.valid_list_cons_recip",
"Prims.eq2",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_region_only",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims._assert",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Buffer.pointer",
"LowStar.Buffer.alloca",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')})
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame:
(h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1))
(ensures (inv h' l1 l2 pos1))))
(post_interrupt: (h: HS.mem -> GTot Type0))
(post_interrupt_frame:
(h: HS.mem -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ post_interrupt h))
(ensures (post_interrupt h'))))
(body:
(pos1: U32.t -> pos2: U32.t
-> HST.Stack bool
(requires
(fun h ->
B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\ valid_list p h0 sl pos2 pos' /\
inv h
(contents_list p h0 sl pos pos1)
(contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos')
pos1))
(ensures
(fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue
then
inv h'
((contents_list p h0 sl pos pos1) `L.append` [contents p h0 sl pos1])
(contents_list p h0 sl pos2 pos')
pos2
else post_interrupt h')))))
: HST.Stack bool
(requires
(fun h ->
h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos))
(ensures
(fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h'))) =
| HST.push_frame ();
let h1 = HST.get () in
let bpos:BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue:BF.pointer bool = BF.alloca true 1ul in
let btest:BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\
(let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\
B.modifies ((Ghost.reveal l) `B.loc_union` (B.loc_region_only true (HS.get_tip h1))) h2 h /\
Seq.index (B.as_seq h btest) 0 ==
((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue
then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1
else post_interrupt h))
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\ cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@@ inline_let ]let while_body ()
: HST.Stack unit (requires (fun h -> test_post true h)) (ensures (fun _ _ h1 -> test_pre h1)) =
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@@ inline_let ]let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while #test_pre
#test_post
(fun (_: unit) ->
(B.index btest 0ul)
<:
HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@@ inline_let ]let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv._sigma0_lemma | val _sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] | val _sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] | let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 55,
"start_col": 0,
"start_line": 51
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._sigma0 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._sigma0 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._sigma0 x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._sigma0",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._sigma0",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | true | false | true | false | false | let _sigma0_lemma #a #m x
: Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] =
| LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv._sigma1_lemma | val _sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] | val _sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] | let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 61,
"start_col": 0,
"start_line": 57
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._sigma1 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._sigma1 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._sigma1 x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._sigma1",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._sigma1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | true | false | true | false | false | let _sigma1_lemma #a #m x
: Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] =
| LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv._Sigma0_lemma | val _Sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] | val _Sigma0_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] | let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 43,
"start_col": 0,
"start_line": 39
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Sigma0 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._Sigma0 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._Sigma0 x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._Sigma0",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._Sigma0",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | true | false | true | false | false | let _Sigma0_lemma #a #m x
: Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] =
| LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv._Maj_lemma | val _Maj_lemma (#a #m x y z: _)
: Lemma
(vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m)
(fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
[SMTPat (_Maj x y z)] | val _Maj_lemma (#a #m x y z: _)
: Lemma
(vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m)
(fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
[SMTPat (_Maj x y z)] | let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 36,
"start_col": 0,
"start_line": 30
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) ->
y: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m) ->
z: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Maj x y z) ==
Lib.Sequence.createi (Hacl.Spec.SHA2.Vec.lanes a m)
(fun i ->
Hacl.Spec.SHA2._Maj a
(Lib.IntVector.vec_v x).[ i ]
(Lib.IntVector.vec_v y).[ i ]
(Lib.IntVector.vec_v z).[ i ])) [SMTPat (Hacl.Spec.SHA2.Vec._Maj x y z)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._Maj",
"Lib.Sequence.createi",
"Spec.Hash.Definitions.word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2._Maj",
"Lib.Sequence.op_String_Access",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.l_and",
"FStar.Seq.Base.length",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | false | false | true | false | false | let _Maj_lemma #a #m x y z
: Lemma
(vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m)
(fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ]))
[SMTPat (_Maj x y z)] =
| LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[ i ] (vec_v y).[ i ] (vec_v z).[ i ])) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_loop_lemma | val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) | val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) | let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 281,
"start_col": 0,
"start_line": 265
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ws0: Hacl.Spec.SHA2.Vec.ws_spec a m ->
st0: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= Hacl.Spec.SHA2.num_rounds16 a}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Lib.LoopCombinators.repeati n Hacl.Spec.SHA2.Vec.shuffle_inner_loop (ws0, st0) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ws_v st_v = _ in
let _ =
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.shuffle_inner_loop a)
((Hacl.Spec.SHA2.Vec.ws_spec_v ws0).[ l ],
(Hacl.Spec.SHA2.Vec.state_spec_v st0).[ l ])
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ws st = _ in
(Hacl.Spec.SHA2.Vec.ws_spec_v ws_v).[ l ] == ws /\
(Hacl.Spec.SHA2.Vec.state_spec_v st_v).[ l ] == st)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.SHA2.num_rounds16",
"Hacl.Spec.SHA2.k_w",
"Spec.Hash.Definitions.words_state",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma_l",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Lib.LoopCombinators.eq_repeati0",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.shuffle_inner_loop",
"Hacl.Spec.SHA2.Vec.shuffle_inner_loop",
"Prims.bool",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Hacl.Spec.SHA2.Equiv.shuffle_loop_lemma",
"Lib.LoopCombinators.repeati",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.ws_spec_v",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v"
] | [
"recursion"
] | false | false | true | false | false | let rec shuffle_loop_lemma #a #m ws0 st0 l n =
| let ws_v, st_v = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[ l ], (state_spec_v st0).[ l ]) in
let ws, st = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0
then
(eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l)
else
let ws_v1, st_v1 = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let ws1, st1 = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv._Sigma1_lemma | val _Sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] | val _Sigma1_lemma (#a #m x: _)
: Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] | let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 49,
"start_col": 0,
"start_line": 45
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Lib.IntVector.vec_t (Spec.Hash.Definitions.word_t a) (Hacl.Spec.SHA2.Vec.lanes a m)
-> FStar.Pervasives.Lemma
(ensures
Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec._Sigma1 x) ==
Lib.Sequence.map (Hacl.Spec.SHA2._Sigma1 a) (Lib.IntVector.vec_v x))
[SMTPat (Hacl.Spec.SHA2.Vec._Sigma1 x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec._Sigma1",
"Lib.Sequence.map",
"Hacl.Spec.SHA2._Sigma1",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Lib.Sequence.lseq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.Nil"
] | [] | true | false | true | false | false | let _Sigma1_lemma #a #m x
: Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] =
| LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.update_last_lemma_l | val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) | val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) | let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 495,
"start_col": 0,
"start_line": 486
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l])) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
totlen: Spec.Hash.Definitions.len_t a ->
len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update_last totlen len b st)).[ l ] ==
Hacl.Spec.SHA2.update_last a totlen len b.(| l |) (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Spec.Hash.Definitions.len_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Spec.Hash.Definitions.block_length",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Equiv.update_lemma_l",
"Prims.unit",
"Hacl.Spec.SHA2.Vec.update",
"Hacl.Spec.SHA2.Equiv.load_last_lemma_l",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.load_last",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.numbytes",
"Spec.Hash.Definitions.len_int_type",
"Lib.ByteSequence.uint_to_bytes_be",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.range",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Lib.IntTypes.shift_left",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.IntTypes.secret",
"FStar.UInt32.__uint_to_t",
"FStar.Mul.op_Star",
"Hacl.Spec.SHA2.Vec.padded_blocks"
] | [] | false | false | true | false | false | let update_last_lemma_l #a #m totlen len b st0 l =
| let blocks = padded_blocks a len in
let fin:nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let b0, b1 = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.ws_next_lemma_loop | val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) | val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) | let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 174,
"start_col": 0,
"start_line": 156
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= 16}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.ws_spec_v (Lib.LoopCombinators.repeati n
Hacl.Spec.SHA2.Vec.ws_next_inner
ws)).[ l ] ==
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.ws_next_inner a)
(Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.SHA2.Equiv.ws_next_inner_lemma_l",
"Prims.unit",
"Lib.LoopCombinators.eq_repeati0",
"Hacl.Spec.SHA2.k_w",
"Hacl.Spec.SHA2.ws_next_inner",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.ws_spec_v",
"Hacl.Spec.SHA2.Vec.ws_next_inner",
"Prims.bool",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Hacl.Spec.SHA2.Equiv.ws_next_lemma_loop",
"Lib.LoopCombinators.repeati"
] | [
"recursion"
] | false | false | true | false | false | let rec ws_next_lemma_loop #a #m ws l n =
| let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[ l ] in
if n = 0
then
(eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[ l ];
ws_next_inner_lemma_l 0 ws l)
else
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[ l ] in
ws_next_lemma_loop #a #m ws l (n - 1);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[ l ] (n - 1);
ws_next_inner_lemma_l (n - 1) lp0 l;
() | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij_subst | val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) | val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) | let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
} | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 390,
"start_col": 0,
"start_line": 359
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Hacl.Spec.SHA2.Vec.multiblock_spec a m ->
j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} ->
i: Prims.nat{i < 16}
-> FStar.Pervasives.Lemma
(ensures
(let l = Hacl.Spec.SHA2.Vec.lanes a m in
(Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec.load_blocks b).[ (i / l) * l + j ]).[ i % l ] ==
Lib.ByteSequence.uint_from_bytes_be (FStar.Seq.Base.slice b.(| j |)
(i * Spec.Hash.Definitions.word_length a)
(i * Spec.Hash.Definitions.word_length a + Spec.Hash.Definitions.word_length a)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.division_addition_lemma",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.euclidean_division_definition",
"FStar.Math.Lemmas.small_div",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Math.Lemmas.small_mod",
"Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij",
"Hacl.Spec.SHA2.Vec.lanes_t"
] | [] | false | false | true | false | false | let load_blocks_lemma_ij_subst #a #m b j i =
| let l = lanes a m in
let i_new = (i / l) * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
calc ( == ) {
i_new % l;
( == ) { () }
((i / l) * l + j) % l;
( == ) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
( == ) { Math.Lemmas.small_mod j l }
j;
};
calc ( == ) {
(i_new / l) * l + j_new;
( == ) { () }
(((i / l) * l + j) / l) * l + i % l;
( == ) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
( == ) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
(i / l) * l + (j / l) * l + i % l;
( == ) { Math.Lemmas.euclidean_division_definition i l }
i + (j / l) * l;
( == ) { Math.Lemmas.small_div j l }
i;
} | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.update_nblocks_lemma_l | val update_nblocks_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_nblocks len b st)).[l] ==
Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) | val update_nblocks_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_nblocks len b st)).[l] ==
Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) | let update_nblocks_lemma_l #a #m len b st l =
let blocks = len / block_length a in
update_nblocks_loop_lemma #a #m len b st l blocks | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 655,
"start_col": 0,
"start_line": 653
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l
val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l]))
let rec update_nblocks_loop_lemma #a #m len b st l n =
let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(|l|) in
let rp = repeati n f_sc (state_spec_v st).[l] in
if n = 0 then begin
eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[l] end
else begin
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[l] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[l] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l end
val update_nblocks_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_nblocks len b st)).[l] ==
Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update_nblocks len b st)).[ l ] ==
Hacl.Spec.SHA2.update_nblocks a len b.(| l |) (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Equiv.update_nblocks_loop_lemma",
"Prims.int",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length",
"Prims.unit"
] | [] | true | false | true | false | false | let update_nblocks_lemma_l #a #m len b st l =
| let blocks = len / block_length a in
update_nblocks_loop_lemma #a #m len b st l blocks | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_core_spec_lemma_l | val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) | val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) | let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 128,
"start_col": 0,
"start_line": 124
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k_t: Hacl.Spec.SHA2.Vec.word a ->
ws_t: Hacl.Spec.SHA2.Vec.element_t a m ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.shuffle_core_spec k_t ws_t st)).[ l ] ==
Hacl.Spec.SHA2.shuffle_core_pre a
k_t
(Lib.IntVector.vec_v ws_t).[ l ]
(Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8_lemma",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.unit",
"Lib.Sequence.eq_intro",
"Spec.Hash.Definitions.state_word_length",
"Hacl.Spec.SHA2.Vec.shuffle_core_spec",
"Hacl.Spec.SHA2.Equiv.shuffle_core_pre_create8"
] | [] | true | false | true | false | false | let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
| eq_intro #(word a)
#(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[ l ]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[ l ] (state_spec_v st).[ l ]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[ l ] (state_spec_v st).[ l ] | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.update_lemma_l | val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l]) | val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l]) | let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 453,
"start_col": 0,
"start_line": 444
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Hacl.Spec.SHA2.Vec.multiblock_spec a m ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update b st)).[ l ] ==
Hacl.Spec.SHA2.update a b.(| l |) (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.state_spec_v_map2_add",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"Lib.Sequence.index",
"Hacl.Spec.SHA2.Vec.op_Plus_Bar",
"Lib.Sequence.map2",
"Prims.unit",
"Hacl.Spec.SHA2.Equiv.shuffle_lemma_l",
"Hacl.Spec.SHA2.Vec.shuffle",
"Hacl.Spec.SHA2.Equiv.load_ws_lemma_l",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.load_ws",
"FStar.Pervasives.reveal_opaque",
"Hacl.Spec.SHA2.Vec.update"
] | [] | true | false | true | false | false | let update_lemma_l #a #m b st l =
| reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 ( +| ) st1 st in
state_spec_v_map2_add #a #m st1 st l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.update_block_lemma_l | val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) | val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) | let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 609,
"start_col": 0,
"start_line": 607
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
i: Prims.nat{i < len / Spec.Hash.Definitions.block_length a} ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.update_block len b i st)).[ l ] ==
Hacl.Spec.SHA2.update_block a len b.(| l |) i (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Equiv.update_lemma_l",
"Hacl.Spec.SHA2.Vec.get_multiblock_spec",
"Prims.unit"
] | [] | true | false | true | false | false | let update_block_lemma_l #a #m len b i st l =
| let mb = get_multiblock_spec len b i in
update_lemma_l mb st l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma | val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) | val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) | let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 233,
"start_col": 0,
"start_line": 217
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Prims.nat{i < Hacl.Spec.SHA2.num_rounds16 a} ->
ws0: Hacl.Spec.SHA2.Vec.ws_spec a m ->
st0: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= 16}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.Vec.shuffle_inner ws0 i)
st0)).[ l ] ==
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.shuffle_inner a (Hacl.Spec.SHA2.Vec.ws_spec_v ws0).[ l ] i)
(Hacl.Spec.SHA2.Vec.state_spec_v st0).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.num_rounds16",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.SHA2.Equiv.shuffle_inner_lemma_l",
"Prims.unit",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Hash.Definitions.words_state",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Hacl.Spec.SHA2.Vec.shuffle_inner",
"Prims.bool",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Hacl.Spec.SHA2.Vec.word",
"Prims.l_or",
"Prims.l_and",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.state_word_length",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.Equiv.shuffle_inner_loop_lemma",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.SHA2.shuffle_inner",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.ws_spec_v"
] | [
"recursion"
] | false | false | true | false | false | let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
| let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[ l ] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[ l ] in
if n = 0
then
(eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[ l ];
shuffle_inner_lemma_l #a #m ws0 i n st0 l)
else
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[ l ] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[ l ] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[ l ] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.hash_lemma | val hash_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) | val hash_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) | let hash_lemma #a #m len b =
Classical.forall_intro (hash_lemma_l #a #m len b) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 688,
"start_col": 0,
"start_line": 687
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l
val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l]))
let rec update_nblocks_loop_lemma #a #m len b st l n =
let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(|l|) in
let rp = repeati n f_sc (state_spec_v st).[l] in
if n = 0 then begin
eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[l] end
else begin
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[l] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[l] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l end
val update_nblocks_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_nblocks len b st)).[l] ==
Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l])
let update_nblocks_lemma_l #a #m len b st l =
let blocks = len / block_length a in
update_nblocks_loop_lemma #a #m len b st l blocks
val hash_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
let hash_lemma_l #a #m len b l =
let len' : len_t a = Spec.mk_len_t a len in
let st0 = init a m in
init_lemma_l a m l;
let st1 = update_nblocks #a #m len b st0 in
update_nblocks_lemma_l #a #m len b st0 l;
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st1 in
update_last_lemma_l len' rem mb st1 l;
finish_lemma_l st l
val hash_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> FStar.Pervasives.Lemma
(ensures
forall (l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}).
(Hacl.Spec.SHA2.Vec.hash len b).(| l |) == Hacl.Spec.SHA2.hash len b.(| l |)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"FStar.Classical.forall_intro",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.IntTypes.uint8",
"Prims.l_or",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.hash_length",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Hacl.Spec.SHA2.Vec.hash",
"Hacl.Spec.SHA2.hash",
"Hacl.Spec.SHA2.Equiv.hash_lemma_l",
"Prims.unit"
] | [] | false | false | true | false | false | let hash_lemma #a #m len b =
| Classical.forall_intro (hash_lemma_l #a #m len b) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij | val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a))) | val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a))) | let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize))) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 345,
"start_col": 0,
"start_line": 316
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a))) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Hacl.Spec.SHA2.Vec.multiblock_spec a m ->
j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} ->
i: Prims.nat{i < 16}
-> FStar.Pervasives.Lemma
(ensures
(let l = Hacl.Spec.SHA2.Vec.lanes a m in
let ind = ((i / l) * l + j) * Spec.Hash.Definitions.word_length a in
(Lib.IntVector.vec_v (Hacl.Spec.SHA2.Vec.load_blocks b).[ i ]).[ j ] ==
Lib.ByteSequence.uint_from_bytes_be (FStar.Seq.Base.slice b.(| i % l |)
ind
(ind + Spec.Hash.Definitions.word_length a)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims._assert",
"Prims.eq2",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.load_blocks",
"Lib.ByteSequence.uint_from_bytes_be",
"FStar.Seq.Base.slice",
"Lib.IntTypes.uint8",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Prims.unit",
"FStar.Seq.Properties.slice_slice",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.paren_mul_right",
"Prims.squash",
"Lib.ByteSequence.index_uints_from_bytes_be",
"Lib.Sequence.lseq",
"Lib.ByteSequence.uints_from_bytes_be",
"FStar.Seq.Base.seq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Spec.Hash.Definitions.word_length",
"Prims.op_Division",
"Prims.op_Modulus",
"Hacl.Spec.SHA2.Vec.lanes_t"
] | [] | false | false | true | false | false | let load_blocks_lemma_ij #a #m b j i =
| let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(| idx_i |) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
assert (vec_v ((load_blocks b).[ i ]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[ i ])).[ j ] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc ( == ) {
idx_j * blocksize_l + j * blocksize;
( == ) { (Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize) }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(| idx_i |)
(idx_j * blocksize_l)
(idx_j * blocksize_l + blocksize_l)
(j * blocksize)
(j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[ i ])).[ j ] ==
BSeq.uint_from_bytes_be (Seq.slice b.(| idx_i |)
((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize))) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.finish_lemma_l | val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) | val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) | let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 592,
"start_col": 0,
"start_line": 591
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.finish st).(| l |) ==
Hacl.Spec.SHA2.finish a (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.store_state_lemma_l",
"Prims.unit"
] | [] | true | false | true | false | false | let finish_lemma_l #a #m st l =
| store_state_lemma_l #a #m st l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.state_spec_v_map2_add | val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 432,
"start_col": 0,
"start_line": 429
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
st1: Hacl.Spec.SHA2.Vec.state_spec a m ->
st2: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Lib.Sequence.map2 Hacl.Spec.SHA2.Vec.op_Plus_Bar st1 st2)).[
l ] ==
Lib.Sequence.map2 Lib.IntTypes.op_Plus_Dot
(Hacl.Spec.SHA2.Vec.state_spec_v st1).[ l ]
(Hacl.Spec.SHA2.Vec.state_spec_v st2).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Hacl.Spec.SHA2.Vec.word",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Lib.Sequence.map2",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Plus_Bar",
"Lib.IntTypes.op_Plus_Dot",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Prims.unit"
] | [] | true | false | true | false | false | let state_spec_v_map2_add #a #m st1 st2 l =
| eq_intro (state_spec_v (map2 ( +| ) st1 st2)).[ l ]
(map2 #_ #_ #_ #8 ( +. ) (state_spec_v st1).[ l ] (state_spec_v st2).[ l ]) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.hash_agile_lemma | val hash_agile_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) | val hash_agile_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) | let hash_agile_lemma #a #m len b =
Classical.forall_intro (hash_agile_lemma_l #a #m len b) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 713,
"start_col": 0,
"start_line": 712
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l
val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l]))
let rec update_nblocks_loop_lemma #a #m len b st l n =
let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(|l|) in
let rp = repeati n f_sc (state_spec_v st).[l] in
if n = 0 then begin
eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[l] end
else begin
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[l] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[l] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l end
val update_nblocks_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_nblocks len b st)).[l] ==
Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l])
let update_nblocks_lemma_l #a #m len b st l =
let blocks = len / block_length a in
update_nblocks_loop_lemma #a #m len b st l blocks
val hash_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
let hash_lemma_l #a #m len b l =
let len' : len_t a = Spec.mk_len_t a len in
let st0 = init a m in
init_lemma_l a m l;
let st1 = update_nblocks #a #m len b st0 in
update_nblocks_lemma_l #a #m len b st0 l;
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st1 in
update_last_lemma_l len' rem mb st1 l;
finish_lemma_l st l
val hash_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
let hash_lemma #a #m len b =
Classical.forall_intro (hash_lemma_l #a #m len b)
val hash_agile_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|))
let hash_agile_lemma_l #a #m len b l =
hash_lemma_l #a #m len b l;
Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma #a len b.(|l|)
val hash_agile_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> FStar.Pervasives.Lemma
(ensures
forall (l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}).
(Hacl.Spec.SHA2.Vec.hash len b).(| l |) == Spec.Agile.Hash.hash a b.(| l |)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"FStar.Classical.forall_intro",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.IntTypes.uint8",
"Prims.l_or",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.hash_length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Hash.Definitions.hash_length'",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Hacl.Spec.SHA2.Vec.hash",
"Spec.Agile.Hash.hash",
"Hacl.Spec.SHA2.Equiv.hash_agile_lemma_l",
"Prims.unit"
] | [] | false | false | true | false | false | let hash_agile_lemma #a #m len b =
| Classical.forall_intro (hash_agile_lemma_l #a #m len b) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.store_state_lemma_l | val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l]) | val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l]) | let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l]) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 571,
"start_col": 0,
"start_line": 558
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m -> l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
Lib.Sequence.sub (Hacl.Spec.SHA2.Vec.store_state st)
(l * (8 * Spec.Hash.Definitions.word_length a))
(8 * Spec.Hash.Definitions.word_length a) ==
Hacl.Spec.SHA2.store_state a (Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.uint8",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.word_length",
"Lib.Sequence.sub",
"Hacl.Spec.SHA2.Vec.store_state",
"Hacl.Spec.SHA2.store_state",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.unit",
"FStar.Classical.forall_intro",
"Prims.eq2",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Prims.op_Addition",
"Prims.op_Multiply",
"Prims.l_True",
"Prims.squash",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.index",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Hacl.Spec.SHA2.Equiv.store_state_lemma_ij",
"Lib.ByteSequence.index_uints_to_bytes_be",
"Spec.Hash.Definitions.word_t",
"Lib.Sequence.lseq",
"Spec.Hash.Definitions.words_state"
] | [] | false | false | true | false | false | let store_state_lemma_l #a #m st l =
| let st_l:words_state a = (state_spec_v st).[ l ] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i: nat{i < 8 * word_length a}) : Lemma (lp.[ l * (8 * word_length a) + i ] == rp.[ i ]) =
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i
in
Classical.forall_intro aux;
eq_intro (sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[ l ]) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.hash_agile_lemma_l | val hash_agile_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) | val hash_agile_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) | let hash_agile_lemma_l #a #m len b l =
hash_lemma_l #a #m len b l;
Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma #a len b.(|l|) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 701,
"start_col": 0,
"start_line": 699
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l
val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l]))
let rec update_nblocks_loop_lemma #a #m len b st l n =
let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(|l|) in
let rp = repeati n f_sc (state_spec_v st).[l] in
if n = 0 then begin
eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[l] end
else begin
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[l] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[l] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l end
val update_nblocks_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_nblocks len b st)).[l] ==
Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l])
let update_nblocks_lemma_l #a #m len b st l =
let blocks = len / block_length a in
update_nblocks_loop_lemma #a #m len b st l blocks
val hash_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
let hash_lemma_l #a #m len b l =
let len' : len_t a = Spec.mk_len_t a len in
let st0 = init a m in
init_lemma_l a m l;
let st1 = update_nblocks #a #m len b st0 in
update_nblocks_lemma_l #a #m len b st0 l;
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st1 in
update_last_lemma_l len' rem mb st1 l;
finish_lemma_l st l
val hash_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len ->
Lemma (forall (l:nat{l < lanes a m}).
(hash #a #m len b).(|l|) == Spec.hash len b.(|l|))
let hash_lemma #a #m len b =
Classical.forall_intro (hash_lemma_l #a #m len b)
val hash_agile_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.Agile.Hash.hash a b.(|l|)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures (Hacl.Spec.SHA2.Vec.hash len b).(| l |) == Spec.Agile.Hash.hash a b.(| l |)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8",
"Prims.unit",
"Hacl.Spec.SHA2.Equiv.hash_lemma_l"
] | [] | true | false | true | false | false | let hash_agile_lemma_l #a #m len b l =
| hash_lemma_l #a #m len b l;
Hacl.Spec.SHA2.EquivScalar.hash_agile_lemma #a len b.(| l |) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.update_nblocks_loop_lemma | val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) | val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) | let rec update_nblocks_loop_lemma #a #m len b st l n =
let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(|l|) in
let rp = repeati n f_sc (state_spec_v st).[l] in
if n = 0 then begin
eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[l] end
else begin
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[l] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[l] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l end | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 639,
"start_col": 0,
"start_line": 624
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l
val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l])) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m} ->
n: Prims.nat{n <= len / Spec.Hash.Definitions.block_length a}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.Vec.update_block len b)
st)).[ l ] ==
Lib.LoopCombinators.repeati n
(Hacl.Spec.SHA2.update_block a len b.(| l |))
(Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Hash.Definitions.words_state",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.unit",
"Hacl.Spec.SHA2.Vec.update_block",
"Prims.bool",
"Hacl.Spec.SHA2.Equiv.update_block_lemma_l",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeati",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Hacl.Spec.SHA2.Vec.word",
"Prims.l_or",
"Prims.l_and",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.state_word_length",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.Equiv.update_nblocks_loop_lemma",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.SHA2.update_block",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8"
] | [
"recursion"
] | false | false | true | false | false | let rec update_nblocks_loop_lemma #a #m len b st l n =
| let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(| l |) in
let rp = repeati n f_sc (state_spec_v st).[ l ] in
if n = 0
then
(eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[ l ])
else
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[ l ] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[ l ] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[ l ] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.hash_lemma_l | val hash_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) | val hash_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) | let hash_lemma_l #a #m len b l =
let len' : len_t a = Spec.mk_len_t a len in
let st0 = init a m in
init_lemma_l a m l;
let st1 = update_nblocks #a #m len b st0 in
update_nblocks_lemma_l #a #m len b st0 l;
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st1 in
update_last_lemma_l len' rem mb st1 l;
finish_lemma_l st l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 676,
"start_col": 0,
"start_line": 666
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a])
let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
}
val store_state_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a) ==
Spec.store_state a (state_spec_v st).[l])
let store_state_lemma_l #a #m st l =
let st_l : words_state a = (state_spec_v st).[l] in
let rp = Spec.store_state a st_l in
let lp = store_state st in
let aux (i:nat{i < 8 * word_length a}) : Lemma (lp.[l * (8 * word_length a) + i] == rp.[i]) =
//assert (rp == BSeq.uints_to_bytes_be #(word_t a) #SEC #8 st_l);
BSeq.index_uints_to_bytes_be #(word_t a) #SEC #8 st_l i;
store_state_lemma_ij #a #m st l i in
Classical.forall_intro aux;
eq_intro
(sub (store_state st) (l * (8 * word_length a)) (8 * word_length a))
(Spec.store_state a (state_spec_v st).[l])
// val emit_lemma_l:
// #a:sha2_alg
// -> #m:m_spec
// -> hseq:lseq uint8 (lanes a m * 8 * word_length a)
// -> l:nat{l < lanes a m} ->
// Lemma ((emit hseq).(|l|) == Spec.emit a (sub hseq (l * (8 * word_length a)) (8 * word_length a)))
// let emit_lemma_l #a #m hseq l = ()
val finish_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((finish st).(|l|) == Spec.finish a (state_spec_v st).[l])
let finish_lemma_l #a #m st l =
store_state_lemma_l #a #m st l
val update_block_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> i:nat{i < len / block_length a}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_block len b i st)).[l] ==
Spec.update_block a len b.(|l|) i (state_spec_v st).[l])
let update_block_lemma_l #a #m len b i st l =
let mb = get_multiblock_spec len b i in
update_lemma_l mb st l
val update_nblocks_loop_lemma:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= len / block_length a } ->
Lemma
((state_spec_v (repeati n (update_block #a #m len b) st)).[l] ==
repeati n (Spec.update_block a len b.(|l|)) ((state_spec_v st).[l]))
let rec update_nblocks_loop_lemma #a #m len b st l n =
let lp = repeati n (update_block #a #m len b) st in
let f_sc = Spec.update_block a len b.(|l|) in
let rp = repeati n f_sc (state_spec_v st).[l] in
if n = 0 then begin
eq_repeati0 n (update_block #a #m len b) st;
eq_repeati0 n f_sc (state_spec_v st).[l] end
else begin
let lp1 = repeati (n - 1) (update_block #a #m len b) st in
let rp1 = repeati (n - 1) f_sc (state_spec_v st).[l] in
update_nblocks_loop_lemma #a #m len b st l (n - 1);
assert ((state_spec_v lp1).[l] == rp1);
unfold_repeati n (update_block #a #m len b) st (n - 1);
unfold_repeati n f_sc (state_spec_v st).[l] (n - 1);
update_block_lemma_l #a #m len b (n - 1) lp1 l end
val update_nblocks_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (update_nblocks len b st)).[l] ==
Spec.update_nblocks a len b.(|l|) (state_spec_v st).[l])
let update_nblocks_lemma_l #a #m len b st l =
let blocks = len / block_length a in
update_nblocks_loop_lemma #a #m len b st l blocks
val hash_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> len:Spec.len_lt_max_a_t a
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma ((hash #a #m len b).(|l|) == Spec.hash len b.(|l|)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures (Hacl.Spec.SHA2.Vec.hash len b).(| l |) == Hacl.Spec.SHA2.hash len b.(| l |)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Equiv.finish_lemma_l",
"Prims.unit",
"Hacl.Spec.SHA2.Equiv.update_last_lemma_l",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.update_last",
"Prims.op_Modulus",
"Spec.Hash.Definitions.block_length",
"Hacl.Spec.SHA2.Vec.get_multilast_spec",
"Prims.int",
"Hacl.Spec.SHA2.Equiv.update_nblocks_lemma_l",
"Hacl.Spec.SHA2.Vec.update_nblocks",
"Hacl.Spec.SHA2.Equiv.init_lemma_l",
"Hacl.Spec.SHA2.Vec.init",
"Spec.Hash.Definitions.len_t",
"Hacl.Spec.SHA2.mk_len_t"
] | [] | true | false | true | false | false | let hash_lemma_l #a #m len b l =
| let len':len_t a = Spec.mk_len_t a len in
let st0 = init a m in
init_lemma_l a m l;
let st1 = update_nblocks #a #m len b st0 in
update_nblocks_lemma_l #a #m len b st0 l;
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st1 in
update_last_lemma_l len' rem mb st1 l;
finish_lemma_l st l | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.load_last_lemma_l | val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) | val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) | let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 472,
"start_col": 0,
"start_line": 469
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
totlen_seq: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.len_length a) ->
fin:
Prims.nat
{ fin == Spec.Hash.Definitions.block_length a \/
fin == 2 * Spec.Hash.Definitions.block_length a } ->
len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.SHA2.Vec.load_last totlen_seq fin len b in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b0_v b1_v = _ in
let _ = Hacl.Spec.SHA2.load_last a totlen_seq fin len b.(| l |) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b0 b1 = _ in
b0_v.(| l |) == b0 /\ b1_v.(| l |) == b1)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.len_length",
"Prims.nat",
"Prims.l_or",
"Prims.eq2",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_disEquality",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.op_LessThan",
"FStar.Pervasives.allow_inversion",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.load_last"
] | [] | true | false | true | false | false | let load_last_lemma_l #a #m totlen_seq fin len b l =
| reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.shuffle_inner_lemma_l | val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) | val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) | let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 202,
"start_col": 0,
"start_line": 199
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
i: Prims.nat{i < Hacl.Spec.SHA2.num_rounds16 a} ->
j: Prims.nat{j < 16} ->
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.state_spec_v (Hacl.Spec.SHA2.Vec.shuffle_inner ws i j st)).[ l ] ==
Hacl.Spec.SHA2.shuffle_inner a
(Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]
i
j
(Hacl.Spec.SHA2.Vec.state_spec_v st).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.num_rounds16",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Equiv.shuffle_core_spec_lemma_l",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.op_String_Access",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.k0",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.unit"
] | [] | true | false | true | false | false | let shuffle_inner_lemma_l #a #m ws i j st l =
| let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[ j ] in
shuffle_core_spec_lemma_l k_t ws_t st l | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.bparse | val bparse (#t: Type0) (p: bare_parser t) (input: bytes) : GTot (option (t * consumed_length input)) | val bparse (#t: Type0) (p: bare_parser t) (input: bytes) : GTot (option (t * consumed_length input)) | let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 50,
"start_col": 0,
"start_line": 45
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: MiniParse.Spec.Base.bare_parser t -> input: MiniParse.Spec.Base.bytes
-> Prims.GTot (FStar.Pervasives.Native.option (t * MiniParse.Spec.Base.consumed_length input)) | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"MiniParse.Spec.Base.bytes",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length"
] | [] | false | false | false | false | false | let bparse (#t: Type0) (p: bare_parser t) (input: bytes) : GTot (option (t * consumed_length input)) =
| p input | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.consumed_length | val consumed_length (b: bytes) : Tot Type0 | val consumed_length (b: bytes) : Tot Type0 | let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } ) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 76,
"end_line": 40,
"start_col": 0,
"start_line": 40
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: MiniParse.Spec.Base.bytes -> Type0 | Prims.Tot | [
"total"
] | [] | [
"MiniParse.Spec.Base.bytes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"MiniParse.Spec.Base.byte"
] | [] | false | false | false | true | true | let consumed_length (b: bytes) : Tot Type0 =
| (n: nat{n <= Seq.length b}) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.bare_parser | val bare_parser (t: Type0) : Tot Type0 | val bare_parser (t: Type0) : Tot Type0 | let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b)) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 91,
"end_line": 43,
"start_col": 0,
"start_line": 43
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } ) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"MiniParse.Spec.Base.bytes",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length"
] | [] | false | false | false | true | true | let bare_parser (t: Type0) : Tot Type0 =
| b: bytes -> GTot (option (t * consumed_length b)) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead_weak_on | val no_lookahead_weak_on (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | val no_lookahead_weak_on (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
))) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 65,
"start_col": 0,
"start_line": 52
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: MiniParse.Spec.Base.bare_parser t ->
x: MiniParse.Spec.Base.bytes ->
x': MiniParse.Spec.Base.bytes
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"MiniParse.Spec.Base.byte",
"Prims.eq2",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"Prims.nat",
"Prims.logical",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | true | let no_lookahead_weak_on (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 =
| Some? (bparse f x) ==>
(let Some v = bparse f x in
let y, off = v in
((off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off
) ==>
Some? (bparse f x') /\
(let Some v' = bparse f x' in
let y', off' = v' in
y == y' /\ (off <: nat) == (off' <: nat)))) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead_weak | val no_lookahead_weak (#t: Type0) (f: bare_parser t) : GTot Type0 | val no_lookahead_weak (#t: Type0) (f: bare_parser t) : GTot Type0 | let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x' | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 85,
"start_col": 0,
"start_line": 81
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: MiniParse.Spec.Base.bare_parser t -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"Prims.l_Forall",
"MiniParse.Spec.Base.bytes",
"MiniParse.Spec.Base.no_lookahead_weak_on"
] | [] | false | false | false | false | true | let no_lookahead_weak (#t: Type0) (f: bare_parser t) : GTot Type0 =
| forall (x: bytes) (x': bytes). no_lookahead_weak_on f x x' | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead_on | val no_lookahead_on (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | val no_lookahead_on (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x' | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 68,
"end_line": 203,
"start_col": 0,
"start_line": 198
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: MiniParse.Spec.Base.bare_parser t ->
x: MiniParse.Spec.Base.bytes ->
x': MiniParse.Spec.Base.bytes
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"MiniParse.Spec.Base.no_lookahead_on_precond",
"MiniParse.Spec.Base.no_lookahead_on_postcond"
] | [] | false | false | false | false | true | let no_lookahead_on (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 =
| no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x' | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.injective | val injective (#t: Type0) (p: bare_parser t) : GTot Type0 | val injective (#t: Type0) (p: bare_parser t) : GTot Type0 | let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2 | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 157,
"start_col": 0,
"start_line": 154
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: MiniParse.Spec.Base.bare_parser t -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"Prims.l_Forall",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"MiniParse.Spec.Base.injective_precond",
"MiniParse.Spec.Base.injective_postcond"
] | [] | false | false | false | false | true | let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
| forall (b1: bytes) (b2: bytes). injective_precond p b1 b2 ==> injective_postcond p b1 b2 | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.injective_precond | val injective_precond (#t: Type0) (p: bare_parser t) (b1 b2: bytes) : GTot Type0 | val injective_precond (#t: Type0) (p: bare_parser t) (b1 b2: bytes) : GTot Type0 | let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 111,
"start_col": 0,
"start_line": 101
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: MiniParse.Spec.Base.bare_parser t ->
b1: MiniParse.Spec.Base.bytes ->
b2: MiniParse.Spec.Base.bytes
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"MiniParse.Spec.Base.bytes",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.eq2",
"Prims.logical",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | true | let injective_precond (#t: Type0) (p: bare_parser t) (b1 b2: bytes) : GTot Type0 =
| Some? (bparse p b1) /\ Some? (bparse p b2) /\
(let Some (v1, len1) = bparse p b1 in
let Some (v2, len2) = bparse p b2 in
v1 == v2) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead | val no_lookahead (#t: Type0) (f: bare_parser t) : GTot Type0 | val no_lookahead (#t: Type0) (f: bare_parser t) : GTot Type0 | let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x' | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 223,
"start_col": 0,
"start_line": 219
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: MiniParse.Spec.Base.bare_parser t -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"Prims.l_Forall",
"MiniParse.Spec.Base.bytes",
"MiniParse.Spec.Base.no_lookahead_on"
] | [] | false | false | false | false | true | let no_lookahead (#t: Type0) (f: bare_parser t) : GTot Type0 =
| forall (x: bytes) (x': bytes). no_lookahead_on f x x' | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.parse | val parse (#t: Type0) (p: parser_spec t) (input: bytes) : GTot (option (t * consumed_length input)) | val parse (#t: Type0) (p: parser_spec t) (input: bytes) : GTot (option (t * consumed_length input)) | let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 255,
"start_col": 0,
"start_line": 250
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: MiniParse.Spec.Base.parser_spec t -> input: MiniParse.Spec.Base.bytes
-> Prims.GTot (FStar.Pervasives.Native.option (t * MiniParse.Spec.Base.consumed_length input)) | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.bytes",
"MiniParse.Spec.Base.bparse",
"MiniParse.Spec.Base.coerce_to_bare_parser",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length"
] | [] | false | false | false | false | false | let parse (#t: Type0) (p: parser_spec t) (input: bytes) : GTot (option (t * consumed_length input)) =
| bparse (coerce_to_bare_parser _ p) input | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.coerce_to_bare_parser | val coerce_to_bare_parser (t: Type0) (p: parser_spec t) : Tot (bare_parser t) | val coerce_to_bare_parser (t: Type0) (p: parser_spec t) : Tot (bare_parser t) | let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 248,
"start_col": 7,
"start_line": 247
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Type0 -> p: MiniParse.Spec.Base.parser_spec t -> MiniParse.Spec.Base.bare_parser t | Prims.Tot | [
"total"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.__proj__Parser__item__f",
"MiniParse.Spec.Base.bare_parser"
] | [] | false | false | false | true | false | let coerce_to_bare_parser (t: Type0) (p: parser_spec t) : Tot (bare_parser t) =
| Parser?.f p | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.bare_serializer | val bare_serializer (t: Type0) : Tot Type0 | val bare_serializer (t: Type0) : Tot Type0 | let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 285,
"start_col": 0,
"start_line": 282
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"MiniParse.Spec.Base.bytes"
] | [] | false | false | false | true | true | let bare_serializer (t: Type0) : Tot Type0 =
| t -> GTot bytes | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead_on_postcond | val no_lookahead_on_postcond (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | val no_lookahead_on_postcond (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
)) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 4,
"end_line": 196,
"start_col": 0,
"start_line": 184
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: MiniParse.Spec.Base.bare_parser t ->
x: MiniParse.Spec.Base.bytes ->
x': MiniParse.Spec.Base.bytes
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.l_and",
"Prims.eq2",
"Prims.logical",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | true | let no_lookahead_on_postcond (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 =
| Some? (bparse f x) ==>
(let Some v = bparse f x in
let y, _ = v in
Some? (bparse f x') /\
(let Some v' = bparse f x' in
let y', _ = v' in
y == y')) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.injective_postcond | val injective_postcond (#t: Type0) (p: bare_parser t) (b1 b2: bytes) : GTot Type0 | val injective_postcond (#t: Type0) (p: bare_parser t) (b1 b2: bytes) : GTot Type0 | let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 138,
"start_col": 0,
"start_line": 127
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: MiniParse.Spec.Base.bare_parser t ->
b1: MiniParse.Spec.Base.bytes ->
b2: MiniParse.Spec.Base.bytes
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"MiniParse.Spec.Base.bytes",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.seq",
"MiniParse.Spec.Base.byte",
"FStar.Seq.Base.slice",
"Prims.logical",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | true | let injective_postcond (#t: Type0) (p: bare_parser t) (b1 b2: bytes) : GTot Type0 =
| Some? (bparse p b1) /\ Some? (bparse p b2) /\
(let Some (v1, len1) = bparse p b1 in
let Some (v2, len2) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\ Seq.slice b1 0 len1 == Seq.slice b2 0 len2) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead_weak_ext | val no_lookahead_weak_ext (#t: Type0) (f1 f2: bare_parser t)
: Lemma (requires ((forall (b: bytes). bparse f2 b == bparse f1 b)))
(ensures (no_lookahead_weak f2 <==> no_lookahead_weak f1)) | val no_lookahead_weak_ext (#t: Type0) (f1 f2: bare_parser t)
: Lemma (requires ((forall (b: bytes). bparse f2 b == bparse f1 b)))
(ensures (no_lookahead_weak f2 <==> no_lookahead_weak f1)) | let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1)) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 98,
"end_line": 97,
"start_col": 0,
"start_line": 87
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f1: MiniParse.Spec.Base.bare_parser t -> f2: MiniParse.Spec.Base.bare_parser t
-> FStar.Pervasives.Lemma
(requires
forall (b: MiniParse.Spec.Base.bytes).
MiniParse.Spec.Base.bparse f2 b == MiniParse.Spec.Base.bparse f1 b)
(ensures
MiniParse.Spec.Base.no_lookahead_weak f2 <==> MiniParse.Spec.Base.no_lookahead_weak f1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"FStar.Classical.forall_intro_2",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.l_iff",
"MiniParse.Spec.Base.no_lookahead_weak_on",
"FStar.Classical.move_requires",
"MiniParse.Spec.Base.no_lookahead_weak_on_ext",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.l_Forall",
"MiniParse.Spec.Base.no_lookahead_weak"
] | [] | false | false | true | false | false | let no_lookahead_weak_ext (#t: Type0) (f1 f2: bare_parser t)
: Lemma (requires ((forall (b: bytes). bparse f2 b == bparse f1 b)))
(ensures (no_lookahead_weak f2 <==> no_lookahead_weak f1)) =
| Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1)) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serialize | val serialize (#t: Type0) (#p: parser_spec t) (s: serializer_spec p) (x: t) : GTot bytes | val serialize (#t: Type0) (#p: parser_spec t) (s: serializer_spec p) (x: t) : GTot bytes | let serialize
(#t: Type0)
(#p: parser_spec t)
(s: serializer_spec p)
(x: t)
: GTot bytes
= Serializer?.f s x | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 384,
"start_col": 0,
"start_line": 378
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)
let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf)
noeq
type serializer_spec
(#t: Type0)
(p: parser_spec t)
= | Serializer : (f: bare_serializer t { serializer_correct p f } ) -> serializer_spec p
unfold
let coerce_serializer
(t2: Type0)
(#t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p))
= s
let serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (fun _ -> True))
= serializer_correct_ext p1 (Serializer?.f s1) p2;
Serializer (Serializer?.f s1 <: bare_serializer t2)
let serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ p1 == p2))
(ensures (fun _ -> True))
= serialize_ext p1 s1 p2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: MiniParse.Spec.Base.serializer_spec p -> x: t -> Prims.GTot MiniParse.Spec.Base.bytes | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.serializer_spec",
"MiniParse.Spec.Base.__proj__Serializer__item__f",
"MiniParse.Spec.Base.bytes"
] | [] | false | false | false | false | false | let serialize (#t: Type0) (#p: parser_spec t) (s: serializer_spec p) (x: t) : GTot bytes =
| Serializer?.f s x | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.store_state_lemma_ij | val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) | val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) | let store_state_lemma_ij #a #m st j i =
let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc (==) { // j_v % blocksize_v / word_length a
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
(==) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) % lanes a m;
};
calc (==) { // j_v / blocksize_v
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
(==) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i) (word_length a) (lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j) }
(8 * j + i / word_length a) / lanes a m;
};
calc (==) {
Seq.index (store_state st) j_v;
(==) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[j_v / blocksize_v])).[j_v % blocksize_v];
(==) { BSeq.index_uints_to_bytes_be (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[(j_v % blocksize_v) % word_length a];
(==) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be
(Seq.index (vec_v st1.[j_v / blocksize_v]) (j_v % blocksize_v / word_length a))).[j_v % word_length a];
(==) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[j_v % word_length a];
(==) { Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a];
} | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 546,
"start_col": 0,
"start_line": 508
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l])
let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l])
#pop-options
val ws_next_lemma_loop:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] ==
repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l])
let rec ws_next_lemma_loop #a #m ws l n =
let lp = repeati n (ws_next_inner #a #m) ws in
let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
if n = 0 then begin
eq_repeati0 n (ws_next_inner #a #m) ws;
eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l];
ws_next_inner_lemma_l 0 ws l end
else begin
let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in
let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in
ws_next_lemma_loop #a #m ws l (n - 1);
//assert ((ws_spec_v lp0).[l] == rp0);
unfold_repeati n (ws_next_inner #a #m) ws (n - 1);
unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1);
//assert (lp == ws_next_inner #a #m (n - 1) lp0);
//assert (rp == Spec.ws_next_inner a (n - 1) rp0);
ws_next_inner_lemma_l (n - 1) lp0 l;
() end
val ws_next_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l])
let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16
val shuffle_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> i:nat{i < Spec.num_rounds16 a}
-> j:nat{j < 16}
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_inner ws i j st)).[l] ==
Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l])
let shuffle_inner_lemma_l #a #m ws i j st l =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec_lemma_l k_t ws_t st l
val shuffle_inner_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= 16} ->
Lemma
((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] ==
repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l])
let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n =
let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in
let lp = repeati n (shuffle_inner ws0 i) st0 in
let rp = repeati n f_sc (state_spec_v st0).[l] in
if n = 0 then begin
eq_repeati0 n (shuffle_inner ws0 i) st0;
eq_repeati0 n f_sc (state_spec_v st0).[l];
shuffle_inner_lemma_l #a #m ws0 i n st0 l end
else begin
let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in
let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in
shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1);
assert ((state_spec_v lp0).[l] == rp0);
unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1);
unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1);
shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end
val shuffle_inner_loop_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < Spec.num_rounds16 a}
-> ws_st:tuple2 (ws_spec a m) (state_spec a m)
-> l:nat{l < lanes a m} ->
Lemma
(let (ws1, st1) = shuffle_inner_loop i ws_st in
let (ws0, st0) = ws_st in
let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st)
let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l =
shuffle_inner_loop_lemma #a #m i ws0 st0 l 16;
ws_next_lemma_l ws0 l
val shuffle_loop_lemma:
#a:sha2_alg
-> #m:m_spec
-> ws0:ws_spec a m
-> st0:state_spec a m
-> l:nat{l < lanes a m}
-> n:nat{n <= Spec.num_rounds16 a} ->
Lemma
(let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
(ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st)
let rec shuffle_loop_lemma #a #m ws0 st0 l n =
let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in
let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in
let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in
if n = 0 then begin
eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0);
eq_repeati0 n (Spec.shuffle_inner_loop a) acc0;
shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end
else begin
let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in
let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in
shuffle_loop_lemma #a #m ws0 st0 l (n - 1);
//assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1);
unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1);
unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1);
shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end
val shuffle_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> ws:ws_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (shuffle ws st)).[l] ==
Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l])
let shuffle_lemma_l #a #m ws st l =
shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a)
val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (init a m)).[l] == Spec.init a)
let init_lemma_l a m l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (init a m)).[l] (Spec.init a)
val load_blocks_lemma_ij:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
let ind = (i / l * l + j) * word_length a in
(vec_v (load_blocks b).[i]).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|i % l|) ind (ind + word_length a)))
let load_blocks_lemma_ij #a #m b j i =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
let blocksize = word_length a in
let blocksize_l = l * blocksize in
let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in
//assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j);
assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j);
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j;
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize)));
calc (==) {
idx_j * blocksize_l + j * blocksize;
(==) { Math.Lemmas.paren_mul_right idx_j l blocksize;
Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize }
(idx_j * l + j) * blocksize;
};
Seq.Properties.slice_slice b.(|idx_i|)
(idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l)
(j * blocksize) (j * blocksize + blocksize);
assert ((vec_v ((load_blocks b).[i])).[j] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize)
((idx_j * l + j) * blocksize + blocksize)))
val load_blocks_lemma_ij_subst:
#a:sha2_alg
-> #m:m_spec
-> b:multiblock_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 16} ->
Lemma (let l = lanes a m in
(vec_v (load_blocks b).[i / l * l + j]).[i % l] ==
BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)))
let load_blocks_lemma_ij_subst #a #m b j i =
let l = lanes a m in
let i_new = i / l * l + j in
let j_new = i % l in
load_blocks_lemma_ij #a #m b j_new i_new;
//assert (
//(vec_v (load_blocks b).[i_new]).[j_new] ==
//BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a)));
calc (==) {
i_new % l;
(==) { }
(i / l * l + j) % l;
(==) { Math.Lemmas.modulo_addition_lemma j l (i / l) }
j % l;
(==) { Math.Lemmas.small_mod j l }
j;
};
calc (==) {
i_new / l * l + j_new;
(==) { }
(i / l * l + j) / l * l + i % l;
(==) { Math.Lemmas.division_addition_lemma j l (i / l) }
(i / l + j / l) * l + i % l;
(==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l }
i / l * l + j / l * l + i % l;
(==) { Math.Lemmas.euclidean_division_definition i l }
i + j / l * l;
(==) { Math.Lemmas.small_div j l }
i;
}
#push-options "--z3rlimit 150"
val load_ws_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> j:nat{j < lanes a m} ->
Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in
let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in
let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) =
let l = lanes a m in
BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i;
assert (Seq.index rp i == BSeq.uint_from_bytes_be
(Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a)));
assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i);
Lemmas.transpose_ws_lemma_ij (load_blocks b) j i;
load_blocks_lemma_ij_subst #a #m b j i in
Classical.forall_intro aux;
eq_intro lp rp
#pop-options
val state_spec_v_map2_add:
#a:sha2_alg
-> #m:m_spec
-> st1:state_spec a m
-> st2:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (map2 (+|) st1 st2)).[l] ==
map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
let state_spec_v_map2_add #a #m st1 st2 l =
eq_intro
(state_spec_v (map2 (+|) st1 st2)).[l]
(map2 #_ #_ #_ #8 (+.) (state_spec_v st1).[l] (state_spec_v st2).[l])
val update_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> b:multiblock_spec a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update b st)).[l] ==
Spec.update a b.(|l|) (state_spec_v st).[l])
let update_lemma_l #a #m b st l =
reveal_opaque (`%update) (update #a #m);
let ws = load_ws b in
load_ws_lemma_l b l;
let st1 = shuffle ws st in
shuffle_lemma_l ws st l;
let res = map2 (+|) st1 st in
state_spec_v_map2_add #a #m st1 st l
val load_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen_seq:lseq uint8 (len_length a)
-> fin:nat{fin == block_length a \/ fin == 2 * block_length a}
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> l:nat{l < lanes a m} ->
Lemma
(let (b0_v, b1_v) = load_last totlen_seq fin len b in
let (b0, b1) = Spec.load_last a totlen_seq fin len b.(|l|) in
b0_v.(|l|) == b0 /\ b1_v.(|l|) == b1)
let load_last_lemma_l #a #m totlen_seq fin len b l =
reveal_opaque (`%load_last) (load_last #a #m);
allow_inversion sha2_alg;
allow_inversion m_spec
val update_last_lemma_l:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> totlen:len_t a
-> len:nat{len <= block_length a}
-> b:multiseq (lanes a m) len
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((state_spec_v (update_last totlen len b st)).[l] ==
Spec.update_last a totlen len b.(|l|) ((state_spec_v st).[l]))
let update_last_lemma_l #a #m totlen len b st0 l =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
load_last_lemma_l #a #m totlen_seq fin len b l;
let st = update b0 st0 in
update_lemma_l b0 st0 l;
update_lemma_l b1 st l
val store_state_lemma_ij:
#a:sha2_alg
-> #m:m_spec{is_supported a m}
-> st:state_spec a m
-> j:nat{j < lanes a m}
-> i:nat{i < 8 * word_length a} ->
Lemma
((store_state st).[j * (8 * word_length a) + i] ==
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[j] (i / word_length a))).[i % word_length a]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
st: Hacl.Spec.SHA2.Vec.state_spec a m ->
j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} ->
i: Prims.nat{i < 8 * Spec.Hash.Definitions.word_length a}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.store_state st).[ j * (8 * Spec.Hash.Definitions.word_length a) + i ] ==
(Lib.ByteSequence.uint_to_bytes_be (FStar.Seq.Base.index (Hacl.Spec.SHA2.Vec.state_spec_v st).[
j ]
(i / Spec.Hash.Definitions.word_length a))).[ i % Spec.Hash.Definitions.word_length a
]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.lanes",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.word_length",
"FStar.Calc.calc_finish",
"Lib.IntTypes.uint8",
"Prims.eq2",
"FStar.Seq.Base.index",
"Hacl.Spec.SHA2.Vec.store_state",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.numbytes",
"Spec.Hash.Definitions.word_t",
"Lib.ByteSequence.uint_to_bytes_be",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.state_spec_v",
"Prims.op_Division",
"Prims.op_Modulus",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.ByteSequence.uints_to_bytes_be",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.IntVector.Serialize.index_vecs_to_bytes_be",
"Prims.squash",
"Lib.ByteSequence.index_uints_to_bytes_be",
"FStar.Math.Lemmas.modulo_modulo_lemma",
"Hacl.Spec.SHA2.Lemmas.transpose_state_lemma_ij",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Math.Lemmas.paren_mul_right",
"Prims.int",
"Prims.op_Addition",
"FStar.Math.Lemmas.division_multiplication_lemma",
"FStar.Math.Lemmas.division_addition_lemma",
"FStar.Math.Lemmas.modulo_division_lemma",
"Hacl.Spec.SHA2.Vec.transpose_state"
] | [] | false | false | true | false | false | let store_state_lemma_ij #a #m st j i =
| let st1 = transpose_state st in
let j_v = j * (8 * word_length a) + i in
let blocksize_v = word_length a * lanes a m in
calc ( == ) {
(j * (8 * word_length a) + i) % blocksize_v / word_length a;
( == ) { Math.Lemmas.modulo_division_lemma (j * (8 * word_length a) + i)
(word_length a)
(lanes a m) }
(j * (8 * word_length a) + i) / word_length a % lanes a m;
( == ) { (Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j)) }
(8 * j + i / word_length a) % lanes a m;
};
calc ( == ) {
(j * (8 * word_length a) + i) / (word_length a * lanes a m);
( == ) { Math.Lemmas.division_multiplication_lemma (j * (8 * word_length a) + i)
(word_length a)
(lanes a m) }
(j * (8 * word_length a) + i) / word_length a / lanes a m;
( == ) { (Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.division_addition_lemma i (word_length a) (8 * j)) }
(8 * j + i / word_length a) / lanes a m;
};
calc ( == ) {
Seq.index (store_state st) j_v;
( == ) { index_vecs_to_bytes_be #(word_t a) #(lanes a m) #8 st1 j_v }
(BSeq.uints_to_bytes_be (vec_v st1.[ j_v / blocksize_v ])).[ j_v % blocksize_v ];
( == ) { BSeq.index_uints_to_bytes_be (vec_v st1.[ j_v / blocksize_v ]) (j_v % blocksize_v) }
(BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[ j_v / blocksize_v ])
(j_v % blocksize_v / word_length a))).[ (j_v % blocksize_v) % word_length a ];
( == ) { Math.Lemmas.modulo_modulo_lemma j_v (word_length a) (lanes a m) }
(BSeq.uint_to_bytes_be (Seq.index (vec_v st1.[ j_v / blocksize_v ])
(j_v % blocksize_v / word_length a))).[ j_v % word_length a ];
( == ) { Lemmas.transpose_state_lemma_ij #a #m st j i }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[ j ] (i / word_length a))).[ j_v %
word_length a ];
( == ) { (Math.Lemmas.paren_mul_right j 8 (word_length a);
Math.Lemmas.modulo_addition_lemma i (word_length a) (j * 8)) }
(BSeq.uint_to_bytes_be (Seq.index (state_spec_v st).[ j ] (i / word_length a))).[ i %
word_length a ];
} | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead_on_precond | val no_lookahead_on_precond (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | val no_lookahead_on_precond (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 | let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 182,
"start_col": 0,
"start_line": 172
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: MiniParse.Spec.Base.bare_parser t ->
x: MiniParse.Spec.Base.bytes ->
x': MiniParse.Spec.Base.bytes
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"MiniParse.Spec.Base.bytes",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"MiniParse.Spec.Base.byte",
"Prims.eq2",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"Prims.logical",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | true | let no_lookahead_on_precond (#t: Type0) (f: bare_parser t) (x x': bytes) : GTot Type0 =
| Some? (bparse f x) /\
(let Some v = bparse f x in
let _, off = v in
off <= Seq.length x' /\ Seq.slice x' 0 off == Seq.slice x 0 off) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serializer_correct | val serializer_correct (#t: Type0) (p: parser_spec t) (f: bare_serializer t) : GTot Type0 | val serializer_correct (#t: Type0) (p: parser_spec t) (f: bare_serializer t) : GTot Type0 | let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x)) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 292,
"start_col": 0,
"start_line": 287
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: MiniParse.Spec.Base.parser_spec t -> f: MiniParse.Spec.Base.bare_serializer t -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.bare_serializer",
"Prims.l_Forall",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.parse",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.length",
"MiniParse.Spec.Base.byte"
] | [] | false | false | false | false | true | let serializer_correct (#t: Type0) (p: parser_spec t) (f: bare_serializer t) : GTot Type0 =
| forall (x: t). parse p (f x) == Some (x, Seq.length (f x)) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.no_lookahead_ext | val no_lookahead_ext (#t: Type0) (p1 p2: bare_parser t)
: Lemma (requires (forall (b: bytes). bparse p2 b == bparse p1 b))
(ensures (no_lookahead p2 <==> no_lookahead p1)) | val no_lookahead_ext (#t: Type0) (p1 p2: bare_parser t)
: Lemma (requires (forall (b: bytes). bparse p2 b == bparse p1 b))
(ensures (no_lookahead p2 <==> no_lookahead p1)) | let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1)) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 93,
"end_line": 235,
"start_col": 0,
"start_line": 225
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p1: MiniParse.Spec.Base.bare_parser t -> p2: MiniParse.Spec.Base.bare_parser t
-> FStar.Pervasives.Lemma
(requires
forall (b: MiniParse.Spec.Base.bytes).
MiniParse.Spec.Base.bparse p2 b == MiniParse.Spec.Base.bparse p1 b)
(ensures MiniParse.Spec.Base.no_lookahead p2 <==> MiniParse.Spec.Base.no_lookahead p1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"FStar.Classical.forall_intro_2",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.l_iff",
"MiniParse.Spec.Base.no_lookahead_on",
"FStar.Classical.move_requires",
"MiniParse.Spec.Base.no_lookahead_on_ext",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.l_Forall",
"MiniParse.Spec.Base.no_lookahead"
] | [] | false | false | true | false | false | let no_lookahead_ext (#t: Type0) (p1 p2: bare_parser t)
: Lemma (requires (forall (b: bytes). bparse p2 b == bparse p1 b))
(ensures (no_lookahead p2 <==> no_lookahead p1)) =
| Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1)) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.injective_ext | val injective_ext (#t: Type0) (p1 p2: bare_parser t)
: Lemma (requires (forall (b: bytes). bparse p2 b == bparse p1 b))
(ensures (injective p2 <==> injective p1)) | val injective_ext (#t: Type0) (p1 p2: bare_parser t)
: Lemma (requires (forall (b: bytes). bparse p2 b == bparse p1 b))
(ensures (injective p2 <==> injective p1)) | let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1)) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 96,
"end_line": 170,
"start_col": 0,
"start_line": 159
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p1: MiniParse.Spec.Base.bare_parser t -> p2: MiniParse.Spec.Base.bare_parser t
-> FStar.Pervasives.Lemma
(requires
forall (b: MiniParse.Spec.Base.bytes).
MiniParse.Spec.Base.bparse p2 b == MiniParse.Spec.Base.bparse p1 b)
(ensures MiniParse.Spec.Base.injective p2 <==> MiniParse.Spec.Base.injective p1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"MiniParse.Spec.Base.bare_parser",
"FStar.Classical.forall_intro_2",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.bparse",
"Prims.l_iff",
"MiniParse.Spec.Base.injective_postcond",
"FStar.Classical.move_requires",
"MiniParse.Spec.Base.injective_postcond_ext",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"MiniParse.Spec.Base.injective_precond",
"MiniParse.Spec.Base.injective_precond_ext",
"Prims.l_Forall",
"MiniParse.Spec.Base.injective"
] | [] | false | false | true | false | false | let injective_ext (#t: Type0) (p1 p2: bare_parser t)
: Lemma (requires (forall (b: bytes). bparse p2 b == bparse p1 b))
(ensures (injective p2 <==> injective p1)) =
| Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1)) | false |
Hacl.Spec.SHA2.Equiv.fst | Hacl.Spec.SHA2.Equiv.ws_next_inner_lemma_l | val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) | val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) | let ws_next_inner_lemma_l #a #m i ws l =
eq_intro #(word a) #16
(ws_spec_v (ws_next_inner i ws)).[l]
(Spec.ws_next_inner a i (ws_spec_v ws).[l]) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 143,
"start_col": 0,
"start_line": 140
} | module Hacl.Spec.SHA2.Equiv
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.IntVector.Serialize
open Lib.LoopCombinators
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
module Lemmas = Hacl.Spec.SHA2.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let _Ch_lemma #a #m x y z :
Lemma (vec_v (_Ch #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Ch x y z)]
=
LSeq.eq_intro (vec_v (_Ch #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Maj_lemma #a #m x y z :
Lemma (vec_v (_Maj #a #m x y z) ==
LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
[SMTPat (_Maj x y z)]
=
LSeq.eq_intro (vec_v (_Maj #a #m x y z))
(LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i]))
let _Sigma0_lemma #a #m x :
Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x))
[SMTPat (_Sigma0 x)]
=
LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x))
let _Sigma1_lemma #a #m x :
Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x))
[SMTPat (_Sigma1 x)]
=
LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x))
let _sigma0_lemma #a #m x :
Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x))
[SMTPat (_sigma0 x)]
=
LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x))
let _sigma1_lemma #a #m x :
Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x))
[SMTPat (_sigma1 x)]
=
LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x))
val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a ->
Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7])
let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 =
let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in
assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8);
assert (length rp == 8);
let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in
let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) =
assert_norm (Seq.index lp i == Seq.index rp i) in
Classical.forall_intro aux;
eq_intro rp lp
val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a
let shuffle_core_pre_create8 a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a ->
Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash)
let shuffle_core_pre_create8_lemma a k_t ws_t hash =
let a0 = Seq.index hash 0 in
let b0 = Seq.index hash 1 in
let c0 = Seq.index hash 2 in
let d0 = Seq.index hash 3 in
let e0 = Seq.index hash 4 in
let f0 = Seq.index hash 5 in
let g0 = Seq.index hash 6 in
let h0 = Seq.index hash 7 in
let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in
let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in
seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0
val shuffle_core_spec_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_spec a m
-> l:nat{l < lanes a m} ->
Lemma
((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] ==
Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l])
let shuffle_core_spec_lemma_l #a #m k_t ws_t st l =
eq_intro #(word a) #(state_word_length a)
(state_spec_v (shuffle_core_spec k_t ws_t st)).[l]
(shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]);
shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l]
#push-options "--z3rlimit 100"
val ws_next_inner_lemma_l:
#a:sha2_alg
-> #m:m_spec
-> i:nat{i < 16}
-> ws:ws_spec a m
-> l:nat{l < lanes a m} ->
Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Lemmas.fst.checked",
"Hacl.Spec.SHA2.EquivScalar.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Equiv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector.Serialize",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Prims.nat{i < 16} ->
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
l: Prims.nat{l < Hacl.Spec.SHA2.Vec.lanes a m}
-> FStar.Pervasives.Lemma
(ensures
(Hacl.Spec.SHA2.Vec.ws_spec_v (Hacl.Spec.SHA2.Vec.ws_next_inner i ws)).[ l ] ==
Hacl.Spec.SHA2.ws_next_inner a i (Hacl.Spec.SHA2.Vec.ws_spec_v ws).[ l ]) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.eq_intro",
"Hacl.Spec.SHA2.Vec.word",
"Lib.Sequence.op_String_Access",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.ws_spec_v",
"Hacl.Spec.SHA2.Vec.ws_next_inner",
"Hacl.Spec.SHA2.ws_next_inner",
"Prims.unit"
] | [] | true | false | true | false | false | let ws_next_inner_lemma_l #a #m i ws l =
| eq_intro #(word a)
#16
(ws_spec_v (ws_next_inner i ws)).[ l ]
(Spec.ws_next_inner a i (ws_spec_v ws).[ l ]) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.coerce_parser | val coerce_parser (t2 #t1: Type0) (p: parser_spec t1)
: Pure (parser_spec t2) (requires (t2 == t1)) (ensures (fun _ -> True)) | val coerce_parser (t2 #t1: Type0) (p: parser_spec t1)
: Pure (parser_spec t2) (requires (t2 == t1)) (ensures (fun _ -> True)) | let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 277,
"start_col": 0,
"start_line": 270
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t2: Type0 -> p: MiniParse.Spec.Base.parser_spec t1
-> Prims.Pure (MiniParse.Spec.Base.parser_spec t2) | Prims.Pure | [] | [] | [
"MiniParse.Spec.Base.parser_spec",
"Prims.eq2",
"Prims.l_True"
] | [] | false | false | false | false | false | let coerce_parser (t2 #t1: Type0) (p: parser_spec t1)
: Pure (parser_spec t2) (requires (t2 == t1)) (ensures (fun _ -> True)) =
| p | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.coerce | val coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) | val coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) | let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 267,
"start_col": 0,
"start_line": 260
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t2: Type -> x: t1 -> Prims.Pure t2 | Prims.Pure | [] | [] | [
"Prims.eq2",
"Prims.l_True"
] | [] | false | false | false | false | false | let coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) =
| (x <: t2) | false |
Spec.Salsa20.fst | Spec.Salsa20.size_block | val size_block : Prims.int | let size_block = 64 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 14,
"start_col": 0,
"start_line": 14
} | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let size_block =
| 64 | false |
|
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serialize_ext' | val serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2) (requires (t1 == t2 /\ p1 == p2)) (ensures (fun _ -> True)) | val serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2) (requires (t1 == t2 /\ p1 == p2)) (ensures (fun _ -> True)) | let serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ p1 == p2))
(ensures (fun _ -> True))
= serialize_ext p1 s1 p2 | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 24,
"end_line": 376,
"start_col": 0,
"start_line": 367
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)
let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf)
noeq
type serializer_spec
(#t: Type0)
(p: parser_spec t)
= | Serializer : (f: bare_serializer t { serializer_correct p f } ) -> serializer_spec p
unfold
let coerce_serializer
(t2: Type0)
(#t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p))
= s
let serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (fun _ -> True))
= serializer_correct_ext p1 (Serializer?.f s1) p2;
Serializer (Serializer?.f s1 <: bare_serializer t2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: MiniParse.Spec.Base.parser_spec t1 ->
s1: MiniParse.Spec.Base.serializer_spec p1 ->
p2: MiniParse.Spec.Base.parser_spec t2
-> Prims.Pure (MiniParse.Spec.Base.serializer_spec p2) | Prims.Pure | [] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.serializer_spec",
"MiniParse.Spec.Base.serialize_ext",
"Prims.l_and",
"Prims.eq2",
"Prims.l_True"
] | [] | false | false | false | false | false | let serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2) (requires (t1 == t2 /\ p1 == p2)) (ensures (fun _ -> True)) =
| serialize_ext p1 s1 p2 | false |
Spec.Salsa20.fst | Spec.Salsa20.size_key | val size_key : Prims.int | let size_key = 32 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let size_key =
| 32 | false |
|
Spec.Salsa20.fst | Spec.Salsa20.size_nonce | val size_nonce : Prims.int | let size_nonce = 8 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let size_nonce =
| 8 | false |
|
Spec.Salsa20.fst | Spec.Salsa20.size_xnonce | val size_xnonce : Prims.int | let size_xnonce = 16 | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 16,
"start_col": 0,
"start_line": 16
} | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let size_xnonce =
| 16 | false |
|
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.coerce_serializer | val coerce_serializer
(t2 #t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p)) | val coerce_serializer
(t2 #t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p)) | let coerce_serializer
(t2: Type0)
(#t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p))
= s | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 353,
"start_col": 0,
"start_line": 346
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)
let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf)
noeq
type serializer_spec
(#t: Type0)
(p: parser_spec t)
= | Serializer : (f: bare_serializer t { serializer_correct p f } ) -> serializer_spec p | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t2: Type0 -> s: MiniParse.Spec.Base.serializer_spec p -> u271: Prims.squash (t2 == t1)
-> MiniParse.Spec.Base.serializer_spec (MiniParse.Spec.Base.coerce_parser t2 p) | Prims.Tot | [
"total"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.serializer_spec",
"Prims.squash",
"Prims.eq2",
"MiniParse.Spec.Base.coerce_parser"
] | [] | false | false | false | false | false | let coerce_serializer
(t2 #t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p)) =
| s | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serialize_ext | val serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input)))
(ensures (fun _ -> True)) | val serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input)))
(ensures (fun _ -> True)) | let serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (fun _ -> True))
= serializer_correct_ext p1 (Serializer?.f s1) p2;
Serializer (Serializer?.f s1 <: bare_serializer t2) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 365,
"start_col": 0,
"start_line": 355
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)
let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf)
noeq
type serializer_spec
(#t: Type0)
(p: parser_spec t)
= | Serializer : (f: bare_serializer t { serializer_correct p f } ) -> serializer_spec p
unfold
let coerce_serializer
(t2: Type0)
(#t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p))
= s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: MiniParse.Spec.Base.parser_spec t1 ->
s1: MiniParse.Spec.Base.serializer_spec p1 ->
p2: MiniParse.Spec.Base.parser_spec t2
-> Prims.Pure (MiniParse.Spec.Base.serializer_spec p2) | Prims.Pure | [] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.serializer_spec",
"MiniParse.Spec.Base.Serializer",
"MiniParse.Spec.Base.__proj__Serializer__item__f",
"MiniParse.Spec.Base.bare_serializer",
"Prims.unit",
"MiniParse.Spec.Base.serializer_correct_ext",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"MiniParse.Spec.Base.bytes",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.parse",
"Prims.l_True"
] | [] | false | false | false | false | false | let serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input)))
(ensures (fun _ -> True)) =
| serializer_correct_ext p1 (Serializer?.f s1) p2;
Serializer (Serializer?.f s1 <: bare_serializer t2) | false |
Spec.Salsa20.fst | Spec.Salsa20.double_round | val double_round:shuffle | val double_round:shuffle | let double_round: shuffle =
column_round @ row_round | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 55,
"start_col": 0,
"start_line": 54
} | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Salsa20.shuffle | Prims.Tot | [
"total"
] | [] | [
"Spec.Salsa20.op_At",
"Spec.Salsa20.state",
"Spec.Salsa20.column_round",
"Spec.Salsa20.row_round"
] | [] | false | false | false | true | false | let double_round:shuffle =
| column_round @ row_round | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serializer_complete | val serializer_complete (#t: Type0) (p: parser_spec t) (f: bare_serializer t) : GTot Type0 | val serializer_complete (#t: Type0) (p: parser_spec t) (f: bare_serializer t) : GTot Type0 | let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 314,
"start_col": 0,
"start_line": 305
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: MiniParse.Spec.Base.parser_spec t -> f: MiniParse.Spec.Base.bare_serializer t -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.bare_serializer",
"Prims.l_Forall",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.parse",
"Prims.eq2",
"FStar.Seq.Base.seq",
"MiniParse.Spec.Base.byte",
"FStar.Seq.Base.slice",
"Prims.logical",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | false | true | let serializer_complete (#t: Type0) (p: parser_spec t) (f: bare_serializer t) : GTot Type0 =
| forall (s: bytes).
Some? (parse p s) ==>
(let Some (x, len) = parse p s in
f x == Seq.slice s 0 len) | false |
Spec.Salsa20.fst | Spec.Salsa20.rounds | val rounds:shuffle | val rounds:shuffle | let rounds : shuffle =
repeat 10 double_round | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 58,
"start_col": 0,
"start_line": 57
} | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state
// Using @ as a functional substitute for ;
let op_At f g = fun x -> g (f x)
let line (a:idx) (b:idx) (d:idx) (s:rotval U32) (m:state) : state =
let m = m.[a] <- (m.[a] ^. ((m.[b] +. m.[d]) <<<. s)) in
m
let quarter_round a b c d : shuffle =
line b a d (size 7) @
line c b a (size 9) @
line d c b (size 13) @
line a d c (size 18)
let column_round : shuffle =
quarter_round 0 4 8 12 @
quarter_round 5 9 13 1 @
quarter_round 10 14 2 6 @
quarter_round 15 3 7 11
let row_round : shuffle =
quarter_round 0 1 2 3 @
quarter_round 5 6 7 4 @
quarter_round 10 11 8 9 @
quarter_round 15 12 13 14
let double_round: shuffle =
column_round @ row_round (* 2 rounds *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Salsa20.shuffle | Prims.Tot | [
"total"
] | [] | [
"Lib.LoopCombinators.repeat",
"Spec.Salsa20.state",
"Spec.Salsa20.double_round"
] | [] | false | false | false | true | false | let rounds:shuffle =
| repeat 10 double_round | false |
Spec.Salsa20.fst | Spec.Salsa20.op_At | val op_At : f: (_: _ -> _) -> g: (_: _ -> _) -> x: _ -> _ | let op_At f g = fun x -> g (f x) | {
"file_name": "specs/Spec.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 29,
"start_col": 0,
"start_line": 29
} | module Spec.Salsa20
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.RawIntTypes
open Lib.LoopCombinators
#set-options "--max_fuel 0 --z3rlimit 100"
(* Constants *)
let size_key = 32 (* in bytes *)
let size_block = 64 (* in bytes *)
let size_nonce = 8 (* in bytes *)
let size_xnonce = 16 (* in bytes *)
type key = lbytes size_key
type block = lbytes size_block
type nonce = lbytes size_nonce
type xnonce = lbytes size_xnonce
type counter = size_nat
type state = lseq uint32 16
type idx = n:size_nat{n < 16}
type shuffle = state -> Tot state | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Salsa20.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: _ -> _) -> g: (_: _ -> _) -> x: _ -> _ | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let ( @ ) f g =
| fun x -> g (f x) | false |
|
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serializer_correct_implies_complete | val serializer_correct_implies_complete (#t: Type0) (p: parser_spec t) (f: bare_serializer t)
: Lemma (requires (serializer_correct p f)) (ensures (serializer_complete p f)) | val serializer_correct_implies_complete (#t: Type0) (p: parser_spec t) (f: bare_serializer t)
: Lemma (requires (serializer_correct p f)) (ensures (serializer_complete p f)) | let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 337,
"start_col": 0,
"start_line": 316
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: MiniParse.Spec.Base.parser_spec t -> f: MiniParse.Spec.Base.bare_serializer t
-> FStar.Pervasives.Lemma (requires MiniParse.Spec.Base.serializer_correct p f)
(ensures MiniParse.Spec.Base.serializer_complete p f) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.bare_serializer",
"FStar.Classical.forall_intro",
"MiniParse.Spec.Base.bytes",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.parse",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"MiniParse.Spec.Base.byte",
"FStar.Seq.Base.slice",
"Prims.logical",
"FStar.Classical.move_requires",
"Prims.unit",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims._assert",
"MiniParse.Spec.Base.injective_postcond",
"MiniParse.Spec.Base.coerce_to_bare_parser",
"MiniParse.Spec.Base.injective_precond",
"MiniParse.Spec.Base.no_lookahead_weak_on",
"FStar.Pervasives.Native.option",
"MiniParse.Spec.Base.serializer_correct",
"MiniParse.Spec.Base.serializer_complete"
] | [] | false | false | true | false | false | let serializer_correct_implies_complete (#t: Type0) (p: parser_spec t) (f: bare_serializer t)
: Lemma (requires (serializer_correct p f)) (ensures (serializer_complete p f)) =
| let prf (s: bytes)
: Lemma (requires (Some? (parse p s)))
(ensures
(Some? (parse p s) /\
(let Some (x, len) = parse p s in
f x == Seq.slice s 0 len))) =
let Some (x, len) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serializer_parser_unique | val serializer_parser_unique (#t: Type0) (p1 p2: parser_spec t) (s: bare_serializer t) (x: bytes)
: Lemma (requires (serializer_correct p1 s /\ serializer_correct p2 s))
(ensures (parse p1 x == parse p2 x)) | val serializer_parser_unique (#t: Type0) (p1 p2: parser_spec t) (s: bare_serializer t) (x: bytes)
: Lemma (requires (serializer_correct p1 s /\ serializer_correct p2 s))
(ensures (parse p1 x == parse p2 x)) | let serializer_parser_unique
(#t: Type0)
(p1: parser_spec t)
(p2: parser_spec t)
(s: bare_serializer t)
(x: bytes)
: Lemma
(requires (
serializer_correct p1 s /\
serializer_correct p2 s
))
(ensures (
parse p1 x == parse p2 x
))
= if Some? (parse p1 x)
then serializer_parser_unique' p1 p2 s x
else if Some? (parse p2 x)
then serializer_parser_unique' p2 p1 s x
else () | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 450,
"start_col": 0,
"start_line": 432
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)
let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf)
noeq
type serializer_spec
(#t: Type0)
(p: parser_spec t)
= | Serializer : (f: bare_serializer t { serializer_correct p f } ) -> serializer_spec p
unfold
let coerce_serializer
(t2: Type0)
(#t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p))
= s
let serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (fun _ -> True))
= serializer_correct_ext p1 (Serializer?.f s1) p2;
Serializer (Serializer?.f s1 <: bare_serializer t2)
let serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ p1 == p2))
(ensures (fun _ -> True))
= serialize_ext p1 s1 p2
let serialize
(#t: Type0)
(#p: parser_spec t)
(s: serializer_spec p)
(x: t)
: GTot bytes
= Serializer?.f s x
let serializer_unique
(#t: Type0)
(p: parser_spec t)
(s1 s2: serializer_spec p)
(x: t)
: Lemma
(serialize s1 x == serialize s2 x)
= serializer_correct_implies_complete p (Serializer?.f s2)
let serializer_injective
(#t: Type0)
(p: parser_spec t)
(s: serializer_spec p)
(x1 x2: t)
: Lemma
(requires (serialize s x1 == serialize s x2))
(ensures (x1 == x2))
= ()
let serializer_parser_unique'
(#t: Type0)
(p1: parser_spec t)
(p2: parser_spec t)
(s: bare_serializer t)
(x: bytes)
: Lemma
(requires (
serializer_correct p1 s /\
serializer_correct p2 s /\
Some? (parse p1 x)
))
(ensures (
parse p1 x == parse p2 x
))
= serializer_correct_implies_complete p1 s;
let (Some (y, len)) = parse p1 x in
let x' = Seq.slice x 0 len in
assert (s y == x');
let len' = Seq.length x' in
assert (len == len');
assert (parse p1 x' == Some (y, len'));
assert (parse p2 x' == Some (y, len'));
assert (no_lookahead_on (coerce_to_bare_parser _ p2) x' x);
assert (no_lookahead_on_postcond (coerce_to_bare_parser _ p2) x' x);
assert (injective_postcond (coerce_to_bare_parser _ p2) x' x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: MiniParse.Spec.Base.parser_spec t ->
p2: MiniParse.Spec.Base.parser_spec t ->
s: MiniParse.Spec.Base.bare_serializer t ->
x: MiniParse.Spec.Base.bytes
-> FStar.Pervasives.Lemma
(requires
MiniParse.Spec.Base.serializer_correct p1 s /\ MiniParse.Spec.Base.serializer_correct p2 s)
(ensures MiniParse.Spec.Base.parse p1 x == MiniParse.Spec.Base.parse p2 x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.bare_serializer",
"MiniParse.Spec.Base.bytes",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.consumed_length",
"MiniParse.Spec.Base.parse",
"MiniParse.Spec.Base.serializer_parser_unique'",
"Prims.bool",
"Prims.unit",
"Prims.l_and",
"MiniParse.Spec.Base.serializer_correct",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let serializer_parser_unique (#t: Type0) (p1 p2: parser_spec t) (s: bare_serializer t) (x: bytes)
: Lemma (requires (serializer_correct p1 s /\ serializer_correct p2 s))
(ensures (parse p1 x == parse p2 x)) =
| if Some? (parse p1 x)
then serializer_parser_unique' p1 p2 s x
else if Some? (parse p2 x) then serializer_parser_unique' p2 p1 s x | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serializer_unique | val serializer_unique (#t: Type0) (p: parser_spec t) (s1 s2: serializer_spec p) (x: t)
: Lemma (serialize s1 x == serialize s2 x) | val serializer_unique (#t: Type0) (p: parser_spec t) (s1 s2: serializer_spec p) (x: t)
: Lemma (serialize s1 x == serialize s2 x) | let serializer_unique
(#t: Type0)
(p: parser_spec t)
(s1 s2: serializer_spec p)
(x: t)
: Lemma
(serialize s1 x == serialize s2 x)
= serializer_correct_implies_complete p (Serializer?.f s2) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 393,
"start_col": 0,
"start_line": 386
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)
let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf)
noeq
type serializer_spec
(#t: Type0)
(p: parser_spec t)
= | Serializer : (f: bare_serializer t { serializer_correct p f } ) -> serializer_spec p
unfold
let coerce_serializer
(t2: Type0)
(#t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p))
= s
let serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (fun _ -> True))
= serializer_correct_ext p1 (Serializer?.f s1) p2;
Serializer (Serializer?.f s1 <: bare_serializer t2)
let serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ p1 == p2))
(ensures (fun _ -> True))
= serialize_ext p1 s1 p2
let serialize
(#t: Type0)
(#p: parser_spec t)
(s: serializer_spec p)
(x: t)
: GTot bytes
= Serializer?.f s x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: MiniParse.Spec.Base.parser_spec t ->
s1: MiniParse.Spec.Base.serializer_spec p ->
s2: MiniParse.Spec.Base.serializer_spec p ->
x: t
-> FStar.Pervasives.Lemma
(ensures MiniParse.Spec.Base.serialize s1 x == MiniParse.Spec.Base.serialize s2 x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.serializer_spec",
"MiniParse.Spec.Base.serializer_correct_implies_complete",
"MiniParse.Spec.Base.__proj__Serializer__item__f",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"MiniParse.Spec.Base.bytes",
"MiniParse.Spec.Base.serialize",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let serializer_unique (#t: Type0) (p: parser_spec t) (s1 s2: serializer_spec p) (x: t)
: Lemma (serialize s1 x == serialize s2 x) =
| serializer_correct_implies_complete p (Serializer?.f s2) | false |
MiniParse.Spec.Base.fst | MiniParse.Spec.Base.serializer_parser_unique' | val serializer_parser_unique' (#t: Type0) (p1 p2: parser_spec t) (s: bare_serializer t) (x: bytes)
: Lemma (requires (serializer_correct p1 s /\ serializer_correct p2 s /\ Some? (parse p1 x)))
(ensures (parse p1 x == parse p2 x)) | val serializer_parser_unique' (#t: Type0) (p1 p2: parser_spec t) (s: bare_serializer t) (x: bytes)
: Lemma (requires (serializer_correct p1 s /\ serializer_correct p2 s /\ Some? (parse p1 x)))
(ensures (parse p1 x == parse p2 x)) | let serializer_parser_unique'
(#t: Type0)
(p1: parser_spec t)
(p2: parser_spec t)
(s: bare_serializer t)
(x: bytes)
: Lemma
(requires (
serializer_correct p1 s /\
serializer_correct p2 s /\
Some? (parse p1 x)
))
(ensures (
parse p1 x == parse p2 x
))
= serializer_correct_implies_complete p1 s;
let (Some (y, len)) = parse p1 x in
let x' = Seq.slice x 0 len in
assert (s y == x');
let len' = Seq.length x' in
assert (len == len');
assert (parse p1 x' == Some (y, len'));
assert (parse p2 x' == Some (y, len'));
assert (no_lookahead_on (coerce_to_bare_parser _ p2) x' x);
assert (no_lookahead_on_postcond (coerce_to_bare_parser _ p2) x' x);
assert (injective_postcond (coerce_to_bare_parser _ p2) x' x) | {
"file_name": "examples/miniparse/MiniParse.Spec.Base.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 430,
"start_col": 0,
"start_line": 405
} | (*
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 MiniParse.Spec.Base
module Seq = FStar.Seq
module U8 = FStar.UInt8
module U32 = FStar.UInt32
inline_for_extraction
type byte = U8.t
type bytes = Seq.seq byte
/// parse a value of type t
///
/// - the parser can fail (currently reporting an uninformative [None])
/// - it returns the parsed value as well as the number of bytes read
/// (this is intended to be the number of bytes to advance the input pointer)
///
/// note that the type now forbids lookahead; the parser cannot depend on
/// values beyond the returned offset
///
/// these parsers are used as specifications, and thus use unrepresentable types
/// such as byte sequences and natural numbers and are always pure
[@@"substitute"]
inline_for_extraction
let consumed_length (b: bytes) : Tot Type0 = (n: nat { n <= Seq.length b } )
inline_for_extraction
let bare_parser (t:Type0) : Tot Type0 = (b: bytes) -> GTot (option (t * consumed_length b))
let bparse
(#t: Type0)
(p: bare_parser t)
(input: bytes)
: GTot (option (t * consumed_length input))
= p input
let no_lookahead_weak_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, off) = v in (
(off <= Seq.length x' /\ Seq.length x' <= Seq.length x /\ Seq.slice x' 0 off == Seq.slice x 0 off) ==>
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', off') = v' in
y == y' /\ (off <: nat) == (off' <: nat)
)))
let no_lookahead_weak_on_ext
(#t: Type0)
(f1 f2: bare_parser t)
(x x' : bytes)
: Lemma
(requires (
bparse f2 x == bparse f1 x /\
bparse f2 x' == bparse f1 x'
))
(ensures (
no_lookahead_weak_on f2 x x' <==> no_lookahead_weak_on f1 x x'
))
= ()
let no_lookahead_weak
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_weak_on f x x'
let no_lookahead_weak_ext
(#t: Type0)
(f1 f2: bare_parser t)
: Lemma
(requires (
(forall (b: bytes) . bparse f2 b == bparse f1 b)
))
(ensures (
no_lookahead_weak f2 <==> no_lookahead_weak f1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_weak_on_ext f1 f2 b1))
(** Injectivity of parsing *)
let injective_precond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
v1 == v2
)
let injective_precond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_precond p2 b1 b2 <==> injective_precond p1 b1 b2
))
= ()
let injective_postcond
(#t: Type0)
(p: bare_parser t)
(b1 b2: bytes)
: GTot Type0
= Some? (bparse p b1) /\
Some? (bparse p b2) /\ (
let (Some (v1, len1)) = bparse p b1 in
let (Some (v2, len2)) = bparse p b2 in
(len1 <: nat) == (len2 <: nat) /\
Seq.slice b1 0 len1 == Seq.slice b2 0 len2
)
let injective_postcond_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
injective_postcond p2 b1 b2 <==> injective_postcond p1 b1 b2
))
= ()
let injective (#t: Type0) (p: bare_parser t) : GTot Type0 =
forall (b1 b2: bytes) .
injective_precond p b1 b2 ==>
injective_postcond p b1 b2
let injective_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
injective p2 <==> injective p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_precond_ext p1 p2 b1));
Classical.forall_intro_2 (fun b1 -> Classical.move_requires (injective_postcond_ext p1 p2 b1))
let no_lookahead_on_precond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) /\ (
let (Some v) = bparse f x in
let (_, off) = v in
off <= Seq.length x' /\
Seq.slice x' 0 off == Seq.slice x 0 off
)
let no_lookahead_on_postcond
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= Some? (bparse f x) ==> (
let (Some v) = bparse f x in
let (y, _) = v in
Some? (bparse f x') /\ (
let (Some v') = bparse f x' in
let (y', _) = v' in
y == y'
))
let no_lookahead_on
(#t: Type0)
(f: bare_parser t)
(x x' : bytes)
: GTot Type0
= no_lookahead_on_precond f x x' ==> no_lookahead_on_postcond f x x'
let no_lookahead_on_ext
(#t: Type0)
(p1 p2: bare_parser t)
(b1 b2: bytes)
: Lemma
(requires (
bparse p2 b1 == bparse p1 b1 /\
bparse p2 b2 == bparse p1 b2
))
(ensures (
no_lookahead_on p2 b1 b2 <==> no_lookahead_on p1 b1 b2
))
= ()
let no_lookahead
(#t: Type0)
(f: bare_parser t)
: GTot Type0
= forall (x x' : bytes) . no_lookahead_on f x x'
let no_lookahead_ext
(#t: Type0)
(p1 p2: bare_parser t)
: Lemma
(requires (
forall (b: bytes) . bparse p2 b == bparse p1 b
))
(ensures (
no_lookahead p2 <==> no_lookahead p1
))
= Classical.forall_intro_2 (fun b1 -> Classical.move_requires (no_lookahead_on_ext p1 p2 b1))
noeq
type parser_spec
(t: Type0)
= | Parser : (f: bare_parser t {
no_lookahead_weak f /\
injective f /\
no_lookahead f
} ) -> parser_spec t
(* AR: see bug#1349 *)
unfold let coerce_to_bare_parser (t:Type0) (p:parser_spec t)
:Tot (bare_parser t) = Parser?.f p
let parse
(#t: Type0)
(p: parser_spec t)
(input: bytes)
: GTot (option (t * consumed_length input))
= bparse (coerce_to_bare_parser _ p) input
(* Coercions *)
unfold
let coerce
(t2: Type)
(#t1: Type)
(x: t1)
: Pure t2
(requires (t1 == t2))
(ensures (fun _ -> True))
= (x <: t2)
unfold
let coerce_parser
(t2: Type0)
(#t1: Type0)
(p: parser_spec t1)
: Pure (parser_spec t2)
(requires (t2 == t1))
(ensures (fun _ -> True))
= p
(* Pure serializers *)
inline_for_extraction
let bare_serializer
(t: Type0)
: Tot Type0
= t -> GTot bytes
let serializer_correct
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (x: t) . parse p (f x) == Some (x, Seq.length (f x))
let serializer_correct_ext
(#t1: Type0)
(p1: parser_spec t1)
(f: bare_serializer t1)
(#t2: Type0)
(p2: parser_spec t2)
: Lemma
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (serializer_correct p1 f <==> serializer_correct p2 f))
= ()
let serializer_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: GTot Type0
= forall (s: bytes) .
Some? (parse p s) ==> (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)
let serializer_correct_implies_complete
(#t: Type0)
(p: parser_spec t)
(f: bare_serializer t)
: Lemma
(requires (serializer_correct p f))
(ensures (serializer_complete p f))
= let prf
(s: bytes)
: Lemma
(requires (Some? (parse p s)))
(ensures (
Some? (parse p s) /\ (
let (Some (x, len)) = parse p s in
f x == Seq.slice s 0 len
)))
= let (Some (x, len)) = parse p s in
assert (no_lookahead_weak_on (coerce_to_bare_parser _ p) (f x) s);
assert (injective_precond (coerce_to_bare_parser _ p) (f x) s);
assert (injective_postcond (coerce_to_bare_parser _ p) (f x) s)
in
Classical.forall_intro (Classical.move_requires prf)
noeq
type serializer_spec
(#t: Type0)
(p: parser_spec t)
= | Serializer : (f: bare_serializer t { serializer_correct p f } ) -> serializer_spec p
unfold
let coerce_serializer
(t2: Type0)
(#t1: Type0)
(#p: parser_spec t1)
(s: serializer_spec p)
(u: squash (t2 == t1))
: Tot (serializer_spec (coerce_parser t2 p))
= s
let serialize_ext
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
(ensures (fun _ -> True))
= serializer_correct_ext p1 (Serializer?.f s1) p2;
Serializer (Serializer?.f s1 <: bare_serializer t2)
let serialize_ext'
(#t1: Type0)
(p1: parser_spec t1)
(s1: serializer_spec p1)
(#t2: Type0)
(p2: parser_spec t2)
: Pure (serializer_spec p2)
(requires (t1 == t2 /\ p1 == p2))
(ensures (fun _ -> True))
= serialize_ext p1 s1 p2
let serialize
(#t: Type0)
(#p: parser_spec t)
(s: serializer_spec p)
(x: t)
: GTot bytes
= Serializer?.f s x
let serializer_unique
(#t: Type0)
(p: parser_spec t)
(s1 s2: serializer_spec p)
(x: t)
: Lemma
(serialize s1 x == serialize s2 x)
= serializer_correct_implies_complete p (Serializer?.f s2)
let serializer_injective
(#t: Type0)
(p: parser_spec t)
(s: serializer_spec p)
(x1 x2: t)
: Lemma
(requires (serialize s x1 == serialize s x2))
(ensures (x1 == x2))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MiniParse.Spec.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "MiniParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: MiniParse.Spec.Base.parser_spec t ->
p2: MiniParse.Spec.Base.parser_spec t ->
s: MiniParse.Spec.Base.bare_serializer t ->
x: MiniParse.Spec.Base.bytes
-> FStar.Pervasives.Lemma
(requires
MiniParse.Spec.Base.serializer_correct p1 s /\ MiniParse.Spec.Base.serializer_correct p2 s /\
Some? (MiniParse.Spec.Base.parse p1 x))
(ensures MiniParse.Spec.Base.parse p1 x == MiniParse.Spec.Base.parse p2 x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"MiniParse.Spec.Base.parser_spec",
"MiniParse.Spec.Base.bare_serializer",
"MiniParse.Spec.Base.bytes",
"MiniParse.Spec.Base.consumed_length",
"Prims._assert",
"MiniParse.Spec.Base.injective_postcond",
"MiniParse.Spec.Base.coerce_to_bare_parser",
"Prims.unit",
"MiniParse.Spec.Base.no_lookahead_on_postcond",
"MiniParse.Spec.Base.no_lookahead_on",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"MiniParse.Spec.Base.parse",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.nat",
"FStar.Seq.Base.length",
"MiniParse.Spec.Base.byte",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"MiniParse.Spec.Base.serializer_correct_implies_complete",
"Prims.l_and",
"MiniParse.Spec.Base.serializer_correct",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let serializer_parser_unique' (#t: Type0) (p1 p2: parser_spec t) (s: bare_serializer t) (x: bytes)
: Lemma (requires (serializer_correct p1 s /\ serializer_correct p2 s /\ Some? (parse p1 x)))
(ensures (parse p1 x == parse p2 x)) =
| serializer_correct_implies_complete p1 s;
let Some (y, len) = parse p1 x in
let x' = Seq.slice x 0 len in
assert (s y == x');
let len' = Seq.length x' in
assert (len == len');
assert (parse p1 x' == Some (y, len'));
assert (parse p2 x' == Some (y, len'));
assert (no_lookahead_on (coerce_to_bare_parser _ p2) x' x);
assert (no_lookahead_on_postcond (coerce_to_bare_parser _ p2) x' x);
assert (injective_postcond (coerce_to_bare_parser _ p2) x' x) | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm128_lemma' | val gcm128_lemma'
(s: Ghost.erased (Seq.seq nat32))
(iv: Ghost.erased supported_iv_LE)
(code: V.va_code)
(_win: bool)
(auth_b: b128)
(auth_bytes auth_num: uint64)
(keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b: b128)
(len128x6_num: uint64)
(in128_b out128_b: b128)
(len128_num: uint64)
(inout_b: b128)
(plain_num: uint64)
(scratch_b tag_b: b128)
(va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b
out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b
va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b
out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b
va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b))) | val gcm128_lemma'
(s: Ghost.erased (Seq.seq nat32))
(iv: Ghost.erased supported_iv_LE)
(code: V.va_code)
(_win: bool)
(auth_b: b128)
(auth_bytes auth_num: uint64)
(keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b: b128)
(len128x6_num: uint64)
(in128_b out128_b: b128)
(len128_num: uint64)
(inout_b: b128)
(plain_num: uint64)
(scratch_b tag_b: b128)
(va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b
out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b
va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b
out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b
va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b))) | let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 196,
"start_col": 0,
"start_line": 128
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE ->
code: Vale.X64.Decls.va_code ->
_win: Prims.bool ->
auth_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
auth_bytes: Vale.Stdcalls.X64.GCMencryptOpt.uint64 ->
auth_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 ->
keys_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
iv_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
hkeys_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
abytes_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
in128x6_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
out128x6_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
len128x6_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 ->
in128_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
out128_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
len128_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 ->
inout_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
plain_num: Vale.Stdcalls.X64.GCMencryptOpt.uint64 ->
scratch_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
tag_b: Vale.Stdcalls.X64.GCMencryptOpt.b128 ->
va_s0: Vale.X64.Decls.va_state
-> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel) | Prims.Ghost | [] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.X64.Decls.va_code",
"Prims.bool",
"Vale.Stdcalls.X64.GCMencryptOpt.b128",
"Vale.Stdcalls.X64.GCMencryptOpt.uint64",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal",
"Vale.Arch.HeapTypes_s.TUInt8",
"Vale.Arch.HeapTypes_s.TUInt128",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.State.vale_state",
"Vale.AES.X64.GCMencryptOpt.va_lemma_Gcm_blocks_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.AES.AES_common_s.AES_128",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"FStar.UInt64.v",
"FStar.Ghost.reveal",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_pre",
"Prims.l_and",
"Vale.X64.Decls.eval_code",
"Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_post",
"Vale.X64.Memory.buffer_writeable"
] | [] | false | false | false | false | false | let gcm128_lemma'
(s: Ghost.erased (Seq.seq nat32))
(iv: Ghost.erased supported_iv_LE)
(code: V.va_code)
(_win: bool)
(auth_b: b128)
(auth_bytes auth_num: uint64)
(keys_b iv_b hkeys_b abytes_b in128x6_b out128x6_b: b128)
(len128x6_num: uint64)
(in128_b out128_b: b128)
(len128_num: uint64)
(inout_b: b128)
(plain_num: uint64)
(scratch_b tag_b: b128)
(va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b
out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b
va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b in128x6_b
out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b
va_s0 va_s1 f /\ ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\ ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b))) =
| let va_s1, f =
GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128 (as_vale_buffer auth_b)
(UInt64.v auth_bytes) (UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b)
(Ghost.reveal iv) (as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b)
(as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.