effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
val generate_sha2_512: generate_st SHA2_512
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let generate_sha2_512 = mk_generate EverCrypt.HMAC.compute_sha2_512
val generate_sha2_512: generate_st SHA2_512 let generate_sha2_512 =
false
null
false
mk_generate EverCrypt.HMAC.compute_sha2_512
{ "checked_file": "EverCrypt.DRBG.fst.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RandomBuffer.System.fsti.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.HMAC_DRBG.fst.checked", "Hacl.HMAC_DRBG.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverCrypt.HMAC.fst.checked" ], "interface_file": true, "source_file": "EverCrypt.DRBG.fst" }
[ "total" ]
[ "EverCrypt.DRBG.mk_generate", "Spec.Hash.Definitions.SHA2_512", "EverCrypt.HMAC.compute_sha2_512" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG open Hacl.HMAC_DRBG open Lib.RandomBuffer.System open LowStar.BufferOps friend Hacl.HMAC_DRBG friend EverCrypt.HMAC #set-options "--max_ifuel 0 --max_fuel 0 --z3rlimit 50" /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it /// /// Respects EverCrypt convention and reverses order of buf_len, buf arguments [@CAbstractStruct] noeq type state_s: supported_alg -> Type0 = | SHA1_s : state SHA1 -> state_s SHA1 | SHA2_256_s: state SHA2_256 -> state_s SHA2_256 | SHA2_384_s: state SHA2_384 -> state_s SHA2_384 | SHA2_512_s: state SHA2_512 -> state_s SHA2_512 let invert_state_s (a:supported_alg): Lemma (requires True) (ensures inversion (state_s a)) [ SMTPat (state_s a) ] = allow_inversion (state_s a) /// Only call this function in extracted code with a known `a` inline_for_extraction noextract let p #a (s:state_s a) : Hacl.HMAC_DRBG.state a = match a with | SHA1 -> let SHA1_s p = s in p | SHA2_256 -> let SHA2_256_s p = s in p | SHA2_384 -> let SHA2_384_s p = s in p | SHA2_512 -> let SHA2_512_s p = s in p let freeable_s #a st = freeable (p st) let footprint_s #a st = footprint (p st) let invariant_s #a st h = invariant (p st) h let repr #a st h = let st = B.get h st 0 in repr (p st) h let loc_includes_union_l_footprint_s #a l1 l2 st = B.loc_includes_union_l l1 l2 (footprint_s st) let invariant_loc_in_footprint #a st m = () let frame_invariant #a l st h0 h1 = () /// State allocation // Would like to specialize alloca in each branch, but two calls to StackInline // functions in the same block lead to variable redefinitions at extraction. let alloca a = let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul let create_in a r = let st = match a with | SHA1 -> SHA1_s (create_in SHA1 r) | SHA2_256 -> SHA2_256_s (create_in SHA2_256 r) | SHA2_384 -> SHA2_384_s (create_in SHA2_384 r) | SHA2_512 -> SHA2_512_s (create_in SHA2_512 r) in B.malloc r st 1ul let create a = create_in a HS.root /// Instantiate function inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a let mk_instantiate #a hmac st personalization_string personalization_string_len = if personalization_string_len >. max_personalization_string_length then false else let entropy_input_len = min_length a in let nonce_len = min_length a /. 2ul in let min_entropy = entropy_input_len +! nonce_len in push_frame(); assert_norm (range (v min_entropy) U32); let entropy = B.alloca (u8 0) min_entropy in let ok = randombytes entropy min_entropy in let result = if not ok then false else begin let entropy_input = B.sub entropy 0ul entropy_input_len in let nonce = B.sub entropy entropy_input_len nonce_len in S.hmac_input_bound a; let st_s = !*st in mk_instantiate hmac (p st_s) entropy_input_len entropy_input nonce_len nonce personalization_string_len personalization_string; true end in pop_frame(); result (** @type: true *) val instantiate_sha1 : instantiate_st SHA1 (** @type: true *) val instantiate_sha2_256: instantiate_st SHA2_256 (** @type: true *) val instantiate_sha2_384: instantiate_st SHA2_384 (** @type: true *) val instantiate_sha2_512: instantiate_st SHA2_512 let instantiate_sha1 = mk_instantiate EverCrypt.HMAC.compute_sha1 let instantiate_sha2_256 = mk_instantiate EverCrypt.HMAC.compute_sha2_256 let instantiate_sha2_384 = mk_instantiate EverCrypt.HMAC.compute_sha2_384 let instantiate_sha2_512 = mk_instantiate EverCrypt.HMAC.compute_sha2_512 /// Reseed function inline_for_extraction noextract val mk_reseed: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> reseed_st a let mk_reseed #a hmac st additional_input additional_input_len = if additional_input_len >. max_additional_input_length then false else let entropy_input_len = min_length a in push_frame(); let entropy_input = B.alloca (u8 0) entropy_input_len in let ok = randombytes entropy_input entropy_input_len in let result = if not ok then false else begin S.hmac_input_bound a; let st_s = !*st in mk_reseed hmac (p st_s) entropy_input_len entropy_input additional_input_len additional_input; true end in pop_frame(); result (** @type: true *) val reseed_sha1 : reseed_st SHA1 (** @type: true *) val reseed_sha2_256: reseed_st SHA2_256 (** @type: true *) val reseed_sha2_384: reseed_st SHA2_384 (** @type: true *) val reseed_sha2_512: reseed_st SHA2_512 let reseed_sha1 = mk_reseed EverCrypt.HMAC.compute_sha1 let reseed_sha2_256 = mk_reseed EverCrypt.HMAC.compute_sha2_256 let reseed_sha2_384 = mk_reseed EverCrypt.HMAC.compute_sha2_384 let reseed_sha2_512 = mk_reseed EverCrypt.HMAC.compute_sha2_512 /// Generate function inline_for_extraction noextract val mk_generate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> generate_st a let mk_generate #a hmac output st n additional_input additional_input_len = if additional_input_len >. max_additional_input_length || n >. max_output_length then false else ( push_frame(); let ok = mk_reseed hmac st additional_input additional_input_len in let result = if not ok then false else begin let st_s = !*st in let b = mk_generate hmac output (p st_s) n additional_input_len additional_input in b (* This used to be true, which is fishy *) end in let h1 = get () in pop_frame(); let h2 = get () in frame_invariant (B.loc_all_regions_from false (HS.get_tip h1)) st h1 h2; result ) (** @type: true *) val generate_sha1 : generate_st SHA1 (** @type: true *) val generate_sha2_256: generate_st SHA2_256 (** @type: true *) val generate_sha2_384: generate_st SHA2_384 (** @type: true *) val generate_sha2_512: generate_st SHA2_512 let generate_sha1 = mk_generate EverCrypt.HMAC.compute_sha1 let generate_sha2_256 = mk_generate EverCrypt.HMAC.compute_sha2_256
false
true
EverCrypt.DRBG.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val generate_sha2_512: generate_st SHA2_512
[]
EverCrypt.DRBG.generate_sha2_512
{ "file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
EverCrypt.DRBG.generate_st Spec.Hash.Definitions.SHA2_512
{ "end_col": 67, "end_line": 243, "start_col": 24, "start_line": 243 }
Prims.Tot
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_uninstantiate a st = let st_s:state_s a = !*st in let s:Hacl.HMAC_DRBG.state a = p st_s in let k:B.buffer uint8 = s.k in let v:B.buffer uint8 = s.v in let ctr:B.buffer size_t = s.reseed_counter in assert (B.disjoint k v /\ B.disjoint k ctr /\ B.disjoint v ctr); assert (B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s st_s)); Lib.Memzero0.memzero k (hash_len a); Lib.Memzero0.memzero v (hash_len a); ctr.(0ul) <- 0ul; B.free k; B.free v; B.free ctr; B.free st
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a let mk_uninstantiate a st =
false
null
false
let st_s:state_s a = !*st in let s:Hacl.HMAC_DRBG.state a = p st_s in let k:B.buffer uint8 = s.k in let v:B.buffer uint8 = s.v in let ctr:B.buffer size_t = s.reseed_counter in assert (B.disjoint k v /\ B.disjoint k ctr /\ B.disjoint v ctr); assert (B.loc_disjoint (B.loc_addr_of_buffer st) (footprint_s st_s)); Lib.Memzero0.memzero k (hash_len a); Lib.Memzero0.memzero v (hash_len a); ctr.(0ul) <- 0ul; B.free k; B.free v; B.free ctr; B.free st
{ "checked_file": "EverCrypt.DRBG.fst.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RandomBuffer.System.fsti.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.HMAC_DRBG.fst.checked", "Hacl.HMAC_DRBG.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverCrypt.HMAC.fst.checked" ], "interface_file": true, "source_file": "EverCrypt.DRBG.fst" }
[ "total" ]
[ "Hacl.HMAC_DRBG.supported_alg", "EverCrypt.DRBG.state", "LowStar.Monotonic.Buffer.free", "EverCrypt.DRBG.state_s", "LowStar.Buffer.trivial_preorder", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "LowStar.BufferOps.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "Lib.Memzero0.memzero", "Hacl.HMAC_DRBG.hash_len", "Prims._assert", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "EverCrypt.DRBG.footprint_s", "Prims.l_and", "LowStar.Monotonic.Buffer.disjoint", "LowStar.Buffer.buffer", "Hacl.HMAC_DRBG.__proj__State__item__reseed_counter", "Hacl.HMAC_DRBG.__proj__State__item__v", "Hacl.HMAC_DRBG.__proj__State__item__k", "Hacl.HMAC_DRBG.state", "EverCrypt.DRBG.p", "LowStar.BufferOps.op_Bang_Star" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG open Hacl.HMAC_DRBG open Lib.RandomBuffer.System open LowStar.BufferOps friend Hacl.HMAC_DRBG friend EverCrypt.HMAC #set-options "--max_ifuel 0 --max_fuel 0 --z3rlimit 50" /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it /// /// Respects EverCrypt convention and reverses order of buf_len, buf arguments [@CAbstractStruct] noeq type state_s: supported_alg -> Type0 = | SHA1_s : state SHA1 -> state_s SHA1 | SHA2_256_s: state SHA2_256 -> state_s SHA2_256 | SHA2_384_s: state SHA2_384 -> state_s SHA2_384 | SHA2_512_s: state SHA2_512 -> state_s SHA2_512 let invert_state_s (a:supported_alg): Lemma (requires True) (ensures inversion (state_s a)) [ SMTPat (state_s a) ] = allow_inversion (state_s a) /// Only call this function in extracted code with a known `a` inline_for_extraction noextract let p #a (s:state_s a) : Hacl.HMAC_DRBG.state a = match a with | SHA1 -> let SHA1_s p = s in p | SHA2_256 -> let SHA2_256_s p = s in p | SHA2_384 -> let SHA2_384_s p = s in p | SHA2_512 -> let SHA2_512_s p = s in p let freeable_s #a st = freeable (p st) let footprint_s #a st = footprint (p st) let invariant_s #a st h = invariant (p st) h let repr #a st h = let st = B.get h st 0 in repr (p st) h let loc_includes_union_l_footprint_s #a l1 l2 st = B.loc_includes_union_l l1 l2 (footprint_s st) let invariant_loc_in_footprint #a st m = () let frame_invariant #a l st h0 h1 = () /// State allocation // Would like to specialize alloca in each branch, but two calls to StackInline // functions in the same block lead to variable redefinitions at extraction. let alloca a = let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul let create_in a r = let st = match a with | SHA1 -> SHA1_s (create_in SHA1 r) | SHA2_256 -> SHA2_256_s (create_in SHA2_256 r) | SHA2_384 -> SHA2_384_s (create_in SHA2_384 r) | SHA2_512 -> SHA2_512_s (create_in SHA2_512 r) in B.malloc r st 1ul let create a = create_in a HS.root /// Instantiate function inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a let mk_instantiate #a hmac st personalization_string personalization_string_len = if personalization_string_len >. max_personalization_string_length then false else let entropy_input_len = min_length a in let nonce_len = min_length a /. 2ul in let min_entropy = entropy_input_len +! nonce_len in push_frame(); assert_norm (range (v min_entropy) U32); let entropy = B.alloca (u8 0) min_entropy in let ok = randombytes entropy min_entropy in let result = if not ok then false else begin let entropy_input = B.sub entropy 0ul entropy_input_len in let nonce = B.sub entropy entropy_input_len nonce_len in S.hmac_input_bound a; let st_s = !*st in mk_instantiate hmac (p st_s) entropy_input_len entropy_input nonce_len nonce personalization_string_len personalization_string; true end in pop_frame(); result (** @type: true *) val instantiate_sha1 : instantiate_st SHA1 (** @type: true *) val instantiate_sha2_256: instantiate_st SHA2_256 (** @type: true *) val instantiate_sha2_384: instantiate_st SHA2_384 (** @type: true *) val instantiate_sha2_512: instantiate_st SHA2_512 let instantiate_sha1 = mk_instantiate EverCrypt.HMAC.compute_sha1 let instantiate_sha2_256 = mk_instantiate EverCrypt.HMAC.compute_sha2_256 let instantiate_sha2_384 = mk_instantiate EverCrypt.HMAC.compute_sha2_384 let instantiate_sha2_512 = mk_instantiate EverCrypt.HMAC.compute_sha2_512 /// Reseed function inline_for_extraction noextract val mk_reseed: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> reseed_st a let mk_reseed #a hmac st additional_input additional_input_len = if additional_input_len >. max_additional_input_length then false else let entropy_input_len = min_length a in push_frame(); let entropy_input = B.alloca (u8 0) entropy_input_len in let ok = randombytes entropy_input entropy_input_len in let result = if not ok then false else begin S.hmac_input_bound a; let st_s = !*st in mk_reseed hmac (p st_s) entropy_input_len entropy_input additional_input_len additional_input; true end in pop_frame(); result (** @type: true *) val reseed_sha1 : reseed_st SHA1 (** @type: true *) val reseed_sha2_256: reseed_st SHA2_256 (** @type: true *) val reseed_sha2_384: reseed_st SHA2_384 (** @type: true *) val reseed_sha2_512: reseed_st SHA2_512 let reseed_sha1 = mk_reseed EverCrypt.HMAC.compute_sha1 let reseed_sha2_256 = mk_reseed EverCrypt.HMAC.compute_sha2_256 let reseed_sha2_384 = mk_reseed EverCrypt.HMAC.compute_sha2_384 let reseed_sha2_512 = mk_reseed EverCrypt.HMAC.compute_sha2_512 /// Generate function inline_for_extraction noextract val mk_generate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> generate_st a let mk_generate #a hmac output st n additional_input additional_input_len = if additional_input_len >. max_additional_input_length || n >. max_output_length then false else ( push_frame(); let ok = mk_reseed hmac st additional_input additional_input_len in let result = if not ok then false else begin let st_s = !*st in let b = mk_generate hmac output (p st_s) n additional_input_len additional_input in b (* This used to be true, which is fishy *) end in let h1 = get () in pop_frame(); let h2 = get () in frame_invariant (B.loc_all_regions_from false (HS.get_tip h1)) st h1 h2; result ) (** @type: true *) val generate_sha1 : generate_st SHA1 (** @type: true *) val generate_sha2_256: generate_st SHA2_256 (** @type: true *) val generate_sha2_384: generate_st SHA2_384 (** @type: true *) val generate_sha2_512: generate_st SHA2_512 let generate_sha1 = mk_generate EverCrypt.HMAC.compute_sha1 let generate_sha2_256 = mk_generate EverCrypt.HMAC.compute_sha2_256 let generate_sha2_384 = mk_generate EverCrypt.HMAC.compute_sha2_384 let generate_sha2_512 = mk_generate EverCrypt.HMAC.compute_sha2_512 /// Uninstantiate function inline_for_extraction noextract
false
false
EverCrypt.DRBG.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
[]
EverCrypt.DRBG.mk_uninstantiate
{ "file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.HMAC_DRBG.supported_alg -> EverCrypt.DRBG.uninstantiate_st a
{ "end_col": 11, "end_line": 263, "start_col": 27, "start_line": 249 }
FStar.HyperStack.ST.StackInline
val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st h1)) /\ invariant st h1)
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let alloca a = let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul
val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st h1)) /\ invariant st h1) let alloca a =
true
null
false
let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul
{ "checked_file": "EverCrypt.DRBG.fst.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RandomBuffer.System.fsti.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.HMAC_DRBG.fst.checked", "Hacl.HMAC_DRBG.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverCrypt.HMAC.fst.checked" ], "interface_file": true, "source_file": "EverCrypt.DRBG.fst" }
[]
[ "Hacl.HMAC_DRBG.supported_alg", "LowStar.Buffer.alloca", "EverCrypt.DRBG.state_s", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "EverCrypt.DRBG.SHA1_s", "Hacl.HMAC_DRBG.state", "Spec.Hash.Definitions.SHA1", "Hacl.HMAC_DRBG.alloca", "EverCrypt.DRBG.SHA2_256_s", "Spec.Hash.Definitions.SHA2_256", "EverCrypt.DRBG.SHA2_384_s", "Spec.Hash.Definitions.SHA2_384", "EverCrypt.DRBG.SHA2_512_s", "Spec.Hash.Definitions.SHA2_512", "EverCrypt.DRBG.state" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG open Hacl.HMAC_DRBG open Lib.RandomBuffer.System open LowStar.BufferOps friend Hacl.HMAC_DRBG friend EverCrypt.HMAC #set-options "--max_ifuel 0 --max_fuel 0 --z3rlimit 50" /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it /// /// Respects EverCrypt convention and reverses order of buf_len, buf arguments [@CAbstractStruct] noeq type state_s: supported_alg -> Type0 = | SHA1_s : state SHA1 -> state_s SHA1 | SHA2_256_s: state SHA2_256 -> state_s SHA2_256 | SHA2_384_s: state SHA2_384 -> state_s SHA2_384 | SHA2_512_s: state SHA2_512 -> state_s SHA2_512 let invert_state_s (a:supported_alg): Lemma (requires True) (ensures inversion (state_s a)) [ SMTPat (state_s a) ] = allow_inversion (state_s a) /// Only call this function in extracted code with a known `a` inline_for_extraction noextract let p #a (s:state_s a) : Hacl.HMAC_DRBG.state a = match a with | SHA1 -> let SHA1_s p = s in p | SHA2_256 -> let SHA2_256_s p = s in p | SHA2_384 -> let SHA2_384_s p = s in p | SHA2_512 -> let SHA2_512_s p = s in p let freeable_s #a st = freeable (p st) let footprint_s #a st = footprint (p st) let invariant_s #a st h = invariant (p st) h let repr #a st h = let st = B.get h st 0 in repr (p st) h let loc_includes_union_l_footprint_s #a l1 l2 st = B.loc_includes_union_l l1 l2 (footprint_s st) let invariant_loc_in_footprint #a st m = () let frame_invariant #a l st h0 h1 = () /// State allocation // Would like to specialize alloca in each branch, but two calls to StackInline
false
false
EverCrypt.DRBG.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val alloca: a:supported_alg -> StackInline (state a) (requires fun _ -> True) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint st h1)) /\ invariant st h1)
[]
EverCrypt.DRBG.alloca
{ "file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.HMAC_DRBG.supported_alg -> FStar.HyperStack.ST.StackInline (EverCrypt.DRBG.state a)
{ "end_col": 17, "end_line": 78, "start_col": 14, "start_line": 70 }
FStar.HyperStack.ST.ST
val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint st h1)) /\ invariant st h1 /\ freeable st h1)
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let create_in a r = let st = match a with | SHA1 -> SHA1_s (create_in SHA1 r) | SHA2_256 -> SHA2_256_s (create_in SHA2_256 r) | SHA2_384 -> SHA2_384_s (create_in SHA2_384 r) | SHA2_512 -> SHA2_512_s (create_in SHA2_512 r) in B.malloc r st 1ul
val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint st h1)) /\ invariant st h1 /\ freeable st h1) let create_in a r =
true
null
false
let st = match a with | SHA1 -> SHA1_s (create_in SHA1 r) | SHA2_256 -> SHA2_256_s (create_in SHA2_256 r) | SHA2_384 -> SHA2_384_s (create_in SHA2_384 r) | SHA2_512 -> SHA2_512_s (create_in SHA2_512 r) in B.malloc r st 1ul
{ "checked_file": "EverCrypt.DRBG.fst.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RandomBuffer.System.fsti.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.HMAC_DRBG.fst.checked", "Hacl.HMAC_DRBG.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverCrypt.HMAC.fst.checked" ], "interface_file": true, "source_file": "EverCrypt.DRBG.fst" }
[]
[ "Hacl.HMAC_DRBG.supported_alg", "FStar.Monotonic.HyperHeap.rid", "LowStar.Buffer.malloc", "EverCrypt.DRBG.state_s", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.trivial_preorder", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Monotonic.Buffer.freeable", "EverCrypt.DRBG.SHA1_s", "Hacl.HMAC_DRBG.state", "Spec.Hash.Definitions.SHA1", "Hacl.HMAC_DRBG.create_in", "EverCrypt.DRBG.SHA2_256_s", "Spec.Hash.Definitions.SHA2_256", "EverCrypt.DRBG.SHA2_384_s", "Spec.Hash.Definitions.SHA2_384", "EverCrypt.DRBG.SHA2_512_s", "Spec.Hash.Definitions.SHA2_512", "EverCrypt.DRBG.state" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG open Hacl.HMAC_DRBG open Lib.RandomBuffer.System open LowStar.BufferOps friend Hacl.HMAC_DRBG friend EverCrypt.HMAC #set-options "--max_ifuel 0 --max_fuel 0 --z3rlimit 50" /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it /// /// Respects EverCrypt convention and reverses order of buf_len, buf arguments [@CAbstractStruct] noeq type state_s: supported_alg -> Type0 = | SHA1_s : state SHA1 -> state_s SHA1 | SHA2_256_s: state SHA2_256 -> state_s SHA2_256 | SHA2_384_s: state SHA2_384 -> state_s SHA2_384 | SHA2_512_s: state SHA2_512 -> state_s SHA2_512 let invert_state_s (a:supported_alg): Lemma (requires True) (ensures inversion (state_s a)) [ SMTPat (state_s a) ] = allow_inversion (state_s a) /// Only call this function in extracted code with a known `a` inline_for_extraction noextract let p #a (s:state_s a) : Hacl.HMAC_DRBG.state a = match a with | SHA1 -> let SHA1_s p = s in p | SHA2_256 -> let SHA2_256_s p = s in p | SHA2_384 -> let SHA2_384_s p = s in p | SHA2_512 -> let SHA2_512_s p = s in p let freeable_s #a st = freeable (p st) let footprint_s #a st = footprint (p st) let invariant_s #a st h = invariant (p st) h let repr #a st h = let st = B.get h st 0 in repr (p st) h let loc_includes_union_l_footprint_s #a l1 l2 st = B.loc_includes_union_l l1 l2 (footprint_s st) let invariant_loc_in_footprint #a st m = () let frame_invariant #a l st h0 h1 = () /// State allocation // Would like to specialize alloca in each branch, but two calls to StackInline // functions in the same block lead to variable redefinitions at extraction. let alloca a = let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul
false
false
EverCrypt.DRBG.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val create_in: a:supported_alg -> r:HS.rid -> ST (state a) (requires fun _ -> is_eternal_region r) (ensures fun h0 st h1 -> B.modifies B.loc_none h0 h1 /\ B.fresh_loc (footprint st h1) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint st h1)) /\ invariant st h1 /\ freeable st h1)
[]
EverCrypt.DRBG.create_in
{ "file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
a: Hacl.HMAC_DRBG.supported_alg -> r: FStar.Monotonic.HyperHeap.rid -> FStar.HyperStack.ST.ST (EverCrypt.DRBG.state a)
{ "end_col": 19, "end_line": 88, "start_col": 19, "start_line": 80 }
Prims.Tot
val mk_reseed: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> reseed_st a
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_reseed #a hmac st additional_input additional_input_len = if additional_input_len >. max_additional_input_length then false else let entropy_input_len = min_length a in push_frame(); let entropy_input = B.alloca (u8 0) entropy_input_len in let ok = randombytes entropy_input entropy_input_len in let result = if not ok then false else begin S.hmac_input_bound a; let st_s = !*st in mk_reseed hmac (p st_s) entropy_input_len entropy_input additional_input_len additional_input; true end in pop_frame(); result
val mk_reseed: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> reseed_st a let mk_reseed #a hmac st additional_input additional_input_len =
false
null
false
if additional_input_len >. max_additional_input_length then false else let entropy_input_len = min_length a in push_frame (); let entropy_input = B.alloca (u8 0) entropy_input_len in let ok = randombytes entropy_input entropy_input_len in let result = if not ok then false else (S.hmac_input_bound a; let st_s = !*st in mk_reseed hmac (p st_s) entropy_input_len entropy_input additional_input_len additional_input; true) in pop_frame (); result
{ "checked_file": "EverCrypt.DRBG.fst.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RandomBuffer.System.fsti.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.HMAC_DRBG.fst.checked", "Hacl.HMAC_DRBG.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverCrypt.HMAC.fst.checked" ], "interface_file": true, "source_file": "EverCrypt.DRBG.fst" }
[ "total" ]
[ "Hacl.HMAC_DRBG.supported_alg", "EverCrypt.HMAC.compute_st", "EverCrypt.DRBG.state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Lib.IntTypes.size_t", "Lib.IntTypes.op_Greater_Dot", "Lib.IntTypes.U32", "Hacl.HMAC_DRBG.max_additional_input_length", "Prims.bool", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Prims.op_Negation", "Hacl.HMAC_DRBG.mk_reseed", "EverCrypt.DRBG.p", "EverCrypt.DRBG.state_s", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "Spec.HMAC_DRBG.hmac_input_bound", "Lib.RandomBuffer.System.randombytes", "LowStar.Monotonic.Buffer.mbuffer", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "Lib.IntTypes.u8", "FStar.HyperStack.ST.push_frame", "Lib.IntTypes.PUB", "Prims.int", "Lib.IntTypes.v", "Spec.HMAC_DRBG.min_length", "Hacl.HMAC_DRBG.min_length" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG open Hacl.HMAC_DRBG open Lib.RandomBuffer.System open LowStar.BufferOps friend Hacl.HMAC_DRBG friend EverCrypt.HMAC #set-options "--max_ifuel 0 --max_fuel 0 --z3rlimit 50" /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it /// /// Respects EverCrypt convention and reverses order of buf_len, buf arguments [@CAbstractStruct] noeq type state_s: supported_alg -> Type0 = | SHA1_s : state SHA1 -> state_s SHA1 | SHA2_256_s: state SHA2_256 -> state_s SHA2_256 | SHA2_384_s: state SHA2_384 -> state_s SHA2_384 | SHA2_512_s: state SHA2_512 -> state_s SHA2_512 let invert_state_s (a:supported_alg): Lemma (requires True) (ensures inversion (state_s a)) [ SMTPat (state_s a) ] = allow_inversion (state_s a) /// Only call this function in extracted code with a known `a` inline_for_extraction noextract let p #a (s:state_s a) : Hacl.HMAC_DRBG.state a = match a with | SHA1 -> let SHA1_s p = s in p | SHA2_256 -> let SHA2_256_s p = s in p | SHA2_384 -> let SHA2_384_s p = s in p | SHA2_512 -> let SHA2_512_s p = s in p let freeable_s #a st = freeable (p st) let footprint_s #a st = footprint (p st) let invariant_s #a st h = invariant (p st) h let repr #a st h = let st = B.get h st 0 in repr (p st) h let loc_includes_union_l_footprint_s #a l1 l2 st = B.loc_includes_union_l l1 l2 (footprint_s st) let invariant_loc_in_footprint #a st m = () let frame_invariant #a l st h0 h1 = () /// State allocation // Would like to specialize alloca in each branch, but two calls to StackInline // functions in the same block lead to variable redefinitions at extraction. let alloca a = let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul let create_in a r = let st = match a with | SHA1 -> SHA1_s (create_in SHA1 r) | SHA2_256 -> SHA2_256_s (create_in SHA2_256 r) | SHA2_384 -> SHA2_384_s (create_in SHA2_384 r) | SHA2_512 -> SHA2_512_s (create_in SHA2_512 r) in B.malloc r st 1ul let create a = create_in a HS.root /// Instantiate function inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a let mk_instantiate #a hmac st personalization_string personalization_string_len = if personalization_string_len >. max_personalization_string_length then false else let entropy_input_len = min_length a in let nonce_len = min_length a /. 2ul in let min_entropy = entropy_input_len +! nonce_len in push_frame(); assert_norm (range (v min_entropy) U32); let entropy = B.alloca (u8 0) min_entropy in let ok = randombytes entropy min_entropy in let result = if not ok then false else begin let entropy_input = B.sub entropy 0ul entropy_input_len in let nonce = B.sub entropy entropy_input_len nonce_len in S.hmac_input_bound a; let st_s = !*st in mk_instantiate hmac (p st_s) entropy_input_len entropy_input nonce_len nonce personalization_string_len personalization_string; true end in pop_frame(); result (** @type: true *) val instantiate_sha1 : instantiate_st SHA1 (** @type: true *) val instantiate_sha2_256: instantiate_st SHA2_256 (** @type: true *) val instantiate_sha2_384: instantiate_st SHA2_384 (** @type: true *) val instantiate_sha2_512: instantiate_st SHA2_512 let instantiate_sha1 = mk_instantiate EverCrypt.HMAC.compute_sha1 let instantiate_sha2_256 = mk_instantiate EverCrypt.HMAC.compute_sha2_256 let instantiate_sha2_384 = mk_instantiate EverCrypt.HMAC.compute_sha2_384 let instantiate_sha2_512 = mk_instantiate EverCrypt.HMAC.compute_sha2_512 /// Reseed function inline_for_extraction noextract val mk_reseed: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> reseed_st a
false
false
EverCrypt.DRBG.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_reseed: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> reseed_st a
[]
EverCrypt.DRBG.mk_reseed
{ "file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hmac: EverCrypt.HMAC.compute_st a -> EverCrypt.DRBG.reseed_st a
{ "end_col": 10, "end_line": 174, "start_col": 2, "start_line": 153 }
Prims.Tot
val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_instantiate #a hmac st personalization_string personalization_string_len = if personalization_string_len >. max_personalization_string_length then false else let entropy_input_len = min_length a in let nonce_len = min_length a /. 2ul in let min_entropy = entropy_input_len +! nonce_len in push_frame(); assert_norm (range (v min_entropy) U32); let entropy = B.alloca (u8 0) min_entropy in let ok = randombytes entropy min_entropy in let result = if not ok then false else begin let entropy_input = B.sub entropy 0ul entropy_input_len in let nonce = B.sub entropy entropy_input_len nonce_len in S.hmac_input_bound a; let st_s = !*st in mk_instantiate hmac (p st_s) entropy_input_len entropy_input nonce_len nonce personalization_string_len personalization_string; true end in pop_frame(); result
val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a let mk_instantiate #a hmac st personalization_string personalization_string_len =
false
null
false
if personalization_string_len >. max_personalization_string_length then false else let entropy_input_len = min_length a in let nonce_len = min_length a /. 2ul in let min_entropy = entropy_input_len +! nonce_len in push_frame (); assert_norm (range (v min_entropy) U32); let entropy = B.alloca (u8 0) min_entropy in let ok = randombytes entropy min_entropy in let result = if not ok then false else let entropy_input = B.sub entropy 0ul entropy_input_len in let nonce = B.sub entropy entropy_input_len nonce_len in S.hmac_input_bound a; let st_s = !*st in mk_instantiate hmac (p st_s) entropy_input_len entropy_input nonce_len nonce personalization_string_len personalization_string; true in pop_frame (); result
{ "checked_file": "EverCrypt.DRBG.fst.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RandomBuffer.System.fsti.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.HMAC_DRBG.fst.checked", "Hacl.HMAC_DRBG.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverCrypt.HMAC.fst.checked" ], "interface_file": true, "source_file": "EverCrypt.DRBG.fst" }
[ "total" ]
[ "Hacl.HMAC_DRBG.supported_alg", "EverCrypt.HMAC.compute_st", "EverCrypt.DRBG.state", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "Lib.IntTypes.size_t", "Lib.IntTypes.op_Greater_Dot", "Lib.IntTypes.U32", "Hacl.HMAC_DRBG.max_personalization_string_length", "Prims.bool", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Prims.op_Negation", "Hacl.HMAC_DRBG.mk_instantiate", "EverCrypt.DRBG.p", "EverCrypt.DRBG.state_s", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "Spec.HMAC_DRBG.hmac_input_bound", "LowStar.Monotonic.Buffer.mbuffer", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "LowStar.Buffer.sub", "FStar.Ghost.hide", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "Lib.RandomBuffer.System.randombytes", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "Prims.b2t", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "Lib.IntTypes.u8", "FStar.Pervasives.assert_norm", "Lib.IntTypes.range", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "FStar.HyperStack.ST.push_frame", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.op_Slash_Dot", "Hacl.HMAC_DRBG.min_length", "Prims.int", "Spec.HMAC_DRBG.min_length" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG open Hacl.HMAC_DRBG open Lib.RandomBuffer.System open LowStar.BufferOps friend Hacl.HMAC_DRBG friend EverCrypt.HMAC #set-options "--max_ifuel 0 --max_fuel 0 --z3rlimit 50" /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it /// /// Respects EverCrypt convention and reverses order of buf_len, buf arguments [@CAbstractStruct] noeq type state_s: supported_alg -> Type0 = | SHA1_s : state SHA1 -> state_s SHA1 | SHA2_256_s: state SHA2_256 -> state_s SHA2_256 | SHA2_384_s: state SHA2_384 -> state_s SHA2_384 | SHA2_512_s: state SHA2_512 -> state_s SHA2_512 let invert_state_s (a:supported_alg): Lemma (requires True) (ensures inversion (state_s a)) [ SMTPat (state_s a) ] = allow_inversion (state_s a) /// Only call this function in extracted code with a known `a` inline_for_extraction noextract let p #a (s:state_s a) : Hacl.HMAC_DRBG.state a = match a with | SHA1 -> let SHA1_s p = s in p | SHA2_256 -> let SHA2_256_s p = s in p | SHA2_384 -> let SHA2_384_s p = s in p | SHA2_512 -> let SHA2_512_s p = s in p let freeable_s #a st = freeable (p st) let footprint_s #a st = footprint (p st) let invariant_s #a st h = invariant (p st) h let repr #a st h = let st = B.get h st 0 in repr (p st) h let loc_includes_union_l_footprint_s #a l1 l2 st = B.loc_includes_union_l l1 l2 (footprint_s st) let invariant_loc_in_footprint #a st m = () let frame_invariant #a l st h0 h1 = () /// State allocation // Would like to specialize alloca in each branch, but two calls to StackInline // functions in the same block lead to variable redefinitions at extraction. let alloca a = let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul let create_in a r = let st = match a with | SHA1 -> SHA1_s (create_in SHA1 r) | SHA2_256 -> SHA2_256_s (create_in SHA2_256 r) | SHA2_384 -> SHA2_384_s (create_in SHA2_384 r) | SHA2_512 -> SHA2_512_s (create_in SHA2_512 r) in B.malloc r st 1ul let create a = create_in a HS.root /// Instantiate function inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a
false
false
EverCrypt.DRBG.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a
[]
EverCrypt.DRBG.mk_instantiate
{ "file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hmac: EverCrypt.HMAC.compute_st a -> EverCrypt.DRBG.instantiate_st a
{ "end_col": 10, "end_line": 124, "start_col": 2, "start_line": 97 }
Prims.Tot
val mk_generate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> generate_st a
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "Lib.RandomBuffer.System", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HMAC_DRBG", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "Spec.HMAC_DRBG", "short_module": "S" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let mk_generate #a hmac output st n additional_input additional_input_len = if additional_input_len >. max_additional_input_length || n >. max_output_length then false else ( push_frame(); let ok = mk_reseed hmac st additional_input additional_input_len in let result = if not ok then false else begin let st_s = !*st in let b = mk_generate hmac output (p st_s) n additional_input_len additional_input in b (* This used to be true, which is fishy *) end in let h1 = get () in pop_frame(); let h2 = get () in frame_invariant (B.loc_all_regions_from false (HS.get_tip h1)) st h1 h2; result )
val mk_generate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> generate_st a let mk_generate #a hmac output st n additional_input additional_input_len =
false
null
false
if additional_input_len >. max_additional_input_length || n >. max_output_length then false else (push_frame (); let ok = mk_reseed hmac st additional_input additional_input_len in let result = if not ok then false else let st_s = !*st in let b = mk_generate hmac output (p st_s) n additional_input_len additional_input in b in let h1 = get () in pop_frame (); let h2 = get () in frame_invariant (B.loc_all_regions_from false (HS.get_tip h1)) st h1 h2; result)
{ "checked_file": "EverCrypt.DRBG.fst.checked", "dependencies": [ "Spec.HMAC_DRBG.fsti.checked", "Spec.Hash.Definitions.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RandomBuffer.System.fsti.checked", "Lib.Memzero0.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.HMAC_DRBG.fst.checked", "Hacl.HMAC_DRBG.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "EverCrypt.HMAC.fst.checked" ], "interface_file": true, "source_file": "EverCrypt.DRBG.fst" }
[ "total" ]
[ "Hacl.HMAC_DRBG.supported_alg", "EverCrypt.HMAC.compute_st", "LowStar.Buffer.buffer", "Lib.IntTypes.uint8", "EverCrypt.DRBG.state", "Lib.IntTypes.size_t", "Prims.op_BarBar", "Lib.IntTypes.op_Greater_Dot", "Lib.IntTypes.U32", "Hacl.HMAC_DRBG.max_additional_input_length", "Hacl.HMAC_DRBG.max_output_length", "Prims.bool", "Prims.unit", "EverCrypt.DRBG.frame_invariant", "LowStar.Monotonic.Buffer.loc_all_regions_from", "FStar.Monotonic.HyperStack.get_tip", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.HyperStack.ST.pop_frame", "Prims.op_Negation", "Hacl.HMAC_DRBG.mk_generate", "EverCrypt.DRBG.p", "EverCrypt.DRBG.state_s", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "EverCrypt.DRBG.mk_reseed", "FStar.HyperStack.ST.push_frame" ]
[]
module EverCrypt.DRBG open FStar.HyperStack.ST open Lib.IntTypes open Spec.Hash.Definitions module HS = FStar.HyperStack module B = LowStar.Buffer module S = Spec.HMAC_DRBG open Hacl.HMAC_DRBG open Lib.RandomBuffer.System open LowStar.BufferOps friend Hacl.HMAC_DRBG friend EverCrypt.HMAC #set-options "--max_ifuel 0 --max_fuel 0 --z3rlimit 50" /// Some duplication from Hacl.HMAC_DRBG because we don't want clients to depend on it /// /// Respects EverCrypt convention and reverses order of buf_len, buf arguments [@CAbstractStruct] noeq type state_s: supported_alg -> Type0 = | SHA1_s : state SHA1 -> state_s SHA1 | SHA2_256_s: state SHA2_256 -> state_s SHA2_256 | SHA2_384_s: state SHA2_384 -> state_s SHA2_384 | SHA2_512_s: state SHA2_512 -> state_s SHA2_512 let invert_state_s (a:supported_alg): Lemma (requires True) (ensures inversion (state_s a)) [ SMTPat (state_s a) ] = allow_inversion (state_s a) /// Only call this function in extracted code with a known `a` inline_for_extraction noextract let p #a (s:state_s a) : Hacl.HMAC_DRBG.state a = match a with | SHA1 -> let SHA1_s p = s in p | SHA2_256 -> let SHA2_256_s p = s in p | SHA2_384 -> let SHA2_384_s p = s in p | SHA2_512 -> let SHA2_512_s p = s in p let freeable_s #a st = freeable (p st) let footprint_s #a st = footprint (p st) let invariant_s #a st h = invariant (p st) h let repr #a st h = let st = B.get h st 0 in repr (p st) h let loc_includes_union_l_footprint_s #a l1 l2 st = B.loc_includes_union_l l1 l2 (footprint_s st) let invariant_loc_in_footprint #a st m = () let frame_invariant #a l st h0 h1 = () /// State allocation // Would like to specialize alloca in each branch, but two calls to StackInline // functions in the same block lead to variable redefinitions at extraction. let alloca a = let st = match a with | SHA1 -> SHA1_s (alloca a) | SHA2_256 -> SHA2_256_s (alloca a) | SHA2_384 -> SHA2_384_s (alloca a) | SHA2_512 -> SHA2_512_s (alloca a) in B.alloca st 1ul let create_in a r = let st = match a with | SHA1 -> SHA1_s (create_in SHA1 r) | SHA2_256 -> SHA2_256_s (create_in SHA2_256 r) | SHA2_384 -> SHA2_384_s (create_in SHA2_384 r) | SHA2_512 -> SHA2_512_s (create_in SHA2_512 r) in B.malloc r st 1ul let create a = create_in a HS.root /// Instantiate function inline_for_extraction noextract val mk_instantiate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> instantiate_st a let mk_instantiate #a hmac st personalization_string personalization_string_len = if personalization_string_len >. max_personalization_string_length then false else let entropy_input_len = min_length a in let nonce_len = min_length a /. 2ul in let min_entropy = entropy_input_len +! nonce_len in push_frame(); assert_norm (range (v min_entropy) U32); let entropy = B.alloca (u8 0) min_entropy in let ok = randombytes entropy min_entropy in let result = if not ok then false else begin let entropy_input = B.sub entropy 0ul entropy_input_len in let nonce = B.sub entropy entropy_input_len nonce_len in S.hmac_input_bound a; let st_s = !*st in mk_instantiate hmac (p st_s) entropy_input_len entropy_input nonce_len nonce personalization_string_len personalization_string; true end in pop_frame(); result (** @type: true *) val instantiate_sha1 : instantiate_st SHA1 (** @type: true *) val instantiate_sha2_256: instantiate_st SHA2_256 (** @type: true *) val instantiate_sha2_384: instantiate_st SHA2_384 (** @type: true *) val instantiate_sha2_512: instantiate_st SHA2_512 let instantiate_sha1 = mk_instantiate EverCrypt.HMAC.compute_sha1 let instantiate_sha2_256 = mk_instantiate EverCrypt.HMAC.compute_sha2_256 let instantiate_sha2_384 = mk_instantiate EverCrypt.HMAC.compute_sha2_384 let instantiate_sha2_512 = mk_instantiate EverCrypt.HMAC.compute_sha2_512 /// Reseed function inline_for_extraction noextract val mk_reseed: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> reseed_st a let mk_reseed #a hmac st additional_input additional_input_len = if additional_input_len >. max_additional_input_length then false else let entropy_input_len = min_length a in push_frame(); let entropy_input = B.alloca (u8 0) entropy_input_len in let ok = randombytes entropy_input entropy_input_len in let result = if not ok then false else begin S.hmac_input_bound a; let st_s = !*st in mk_reseed hmac (p st_s) entropy_input_len entropy_input additional_input_len additional_input; true end in pop_frame(); result (** @type: true *) val reseed_sha1 : reseed_st SHA1 (** @type: true *) val reseed_sha2_256: reseed_st SHA2_256 (** @type: true *) val reseed_sha2_384: reseed_st SHA2_384 (** @type: true *) val reseed_sha2_512: reseed_st SHA2_512 let reseed_sha1 = mk_reseed EverCrypt.HMAC.compute_sha1 let reseed_sha2_256 = mk_reseed EverCrypt.HMAC.compute_sha2_256 let reseed_sha2_384 = mk_reseed EverCrypt.HMAC.compute_sha2_384 let reseed_sha2_512 = mk_reseed EverCrypt.HMAC.compute_sha2_512 /// Generate function inline_for_extraction noextract val mk_generate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> generate_st a
false
false
EverCrypt.DRBG.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_generate: #a:supported_alg -> EverCrypt.HMAC.compute_st a -> generate_st a
[]
EverCrypt.DRBG.mk_generate
{ "file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
hmac: EverCrypt.HMAC.compute_st a -> EverCrypt.DRBG.generate_st a
{ "end_col": 10, "end_line": 222, "start_col": 2, "start_line": 202 }
Prims.Tot
val sealBase: sealBase_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sealBase = hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp256 setupBaseS
val sealBase: sealBase_st cs True let sealBase =
false
null
false
hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp256 setupBaseS
{ "checked_file": "Hacl.HPKE.P256_CP256_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.P256_CP256_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_sealBase_higher", "Hacl.HPKE.P256_CP256_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.AEAD.aead_encrypt_cp256", "Hacl.HPKE.P256_CP256_SHA256.setupBaseS" ]
[]
module Hacl.HPKE.P256_CP256_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0" let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256
false
true
Hacl.HPKE.P256_CP256_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sealBase: sealBase_st cs True
[]
Hacl.HPKE.P256_CP256_SHA256.sealBase
{ "file_name": "code/hpke/Hacl.HPKE.P256_CP256_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.sealBase_st Hacl.HPKE.P256_CP256_SHA256.cs Prims.l_True
{ "end_col": 80, "end_line": 18, "start_col": 15, "start_line": 18 }
Prims.Tot
val openBase: openBase_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let openBase = hpke_openBase_higher #cs True IAEAD.aead_decrypt_cp256 setupBaseR
val openBase: openBase_st cs True let openBase =
false
null
false
hpke_openBase_higher #cs True IAEAD.aead_decrypt_cp256 setupBaseR
{ "checked_file": "Hacl.HPKE.P256_CP256_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.P256_CP256_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_openBase_higher", "Hacl.HPKE.P256_CP256_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.AEAD.aead_decrypt_cp256", "Hacl.HPKE.P256_CP256_SHA256.setupBaseR" ]
[]
module Hacl.HPKE.P256_CP256_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0" let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 let sealBase = hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp256 setupBaseS
false
true
Hacl.HPKE.P256_CP256_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val openBase: openBase_st cs True
[]
Hacl.HPKE.P256_CP256_SHA256.openBase
{ "file_name": "code/hpke/Hacl.HPKE.P256_CP256_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.openBase_st Hacl.HPKE.P256_CP256_SHA256.cs Prims.l_True
{ "end_col": 80, "end_line": 20, "start_col": 15, "start_line": 20 }
Prims.Tot
val setupBaseS: setupBaseS_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256
val setupBaseS: setupBaseS_st cs True let setupBaseS =
false
null
false
hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256
{ "checked_file": "Hacl.HPKE.P256_CP256_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.P256_CP256_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_setupBaseS_higher", "Hacl.HPKE.P256_CP256_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.HKDF.hkdf_expand256", "Hacl.HPKE.Interface.HKDF.hkdf_extract256", "Hacl.HPKE.Interface.DH.secret_to_public_p256", "Hacl.HPKE.Interface.DH.dh_p256" ]
[]
module Hacl.HPKE.P256_CP256_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0"
false
true
Hacl.HPKE.P256_CP256_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val setupBaseS: setupBaseS_st cs True
[]
Hacl.HPKE.P256_CP256_SHA256.setupBaseS
{ "file_name": "code/hpke/Hacl.HPKE.P256_CP256_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.setupBaseS_st Hacl.HPKE.P256_CP256_SHA256.cs Prims.l_True
{ "end_col": 164, "end_line": 14, "start_col": 17, "start_line": 14 }
Prims.Tot
val setupBaseR: setupBaseR_st cs True
[ { "abbrev": true, "full_module": "Hacl.HPKE.Interface.AEAD", "short_module": "IAEAD" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.Hash", "short_module": "IHash" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.HKDF", "short_module": "IHK" }, { "abbrev": true, "full_module": "Hacl.HPKE.Interface.DH", "short_module": "IDH" }, { "abbrev": false, "full_module": "Hacl.Meta.HPKE", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256
val setupBaseR: setupBaseR_st cs True let setupBaseR =
false
null
false
hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256
{ "checked_file": "Hacl.HPKE.P256_CP256_SHA256.fst.checked", "dependencies": [ "prims.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.Meta.HPKE.fst.checked", "Hacl.HPKE.Interface.HKDF.fst.checked", "Hacl.HPKE.Interface.Hash.fst.checked", "Hacl.HPKE.Interface.DH.fst.checked", "Hacl.HPKE.Interface.AEAD.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.HPKE.P256_CP256_SHA256.fst" }
[ "total" ]
[ "Hacl.Meta.HPKE.hpke_setupBaseR_higher", "Hacl.HPKE.P256_CP256_SHA256.cs", "Prims.l_True", "Hacl.HPKE.Interface.HKDF.hkdf_expand256", "Hacl.HPKE.Interface.HKDF.hkdf_extract256", "Hacl.HPKE.Interface.DH.dh_p256", "Hacl.HPKE.Interface.DH.secret_to_public_p256" ]
[]
module Hacl.HPKE.P256_CP256_SHA256 open Hacl.Meta.HPKE module IDH = Hacl.HPKE.Interface.DH module IHK = Hacl.HPKE.Interface.HKDF module IHash = Hacl.HPKE.Interface.Hash module IAEAD = Hacl.HPKE.Interface.AEAD friend Hacl.Meta.HPKE #set-options "--fuel 0 --ifuel 0" let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256
false
true
Hacl.HPKE.P256_CP256_SHA256.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val setupBaseR: setupBaseR_st cs True
[]
Hacl.HPKE.P256_CP256_SHA256.setupBaseR
{ "file_name": "code/hpke/Hacl.HPKE.P256_CP256_SHA256.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Hacl.Impl.HPKE.setupBaseR_st Hacl.HPKE.P256_CP256_SHA256.cs Prims.l_True
{ "end_col": 164, "end_line": 16, "start_col": 17, "start_line": 16 }
Prims.Tot
val parse_der_length_payload_kind_weak:parser_kind
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None
val parse_der_length_payload_kind_weak:parser_kind let parse_der_length_payload_kind_weak:parser_kind =
false
null
false
strong_parser_kind 0 126 None
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.Base.strong_parser_kind", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.parser_kind_metadata_some" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction
false
true
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_der_length_payload_kind_weak:parser_kind
[]
LowParse.Spec.DER.parse_der_length_payload_kind_weak
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser_kind
{ "end_col": 31, "end_line": 215, "start_col": 2, "start_line": 215 }
Prims.Tot
val parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max)
val parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind =
false
null
false
and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.DER.parse_bounded_der_length_payload_kind", "LowParse.Spec.Base.parser_kind" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind
[]
LowParse.Spec.DER.parse_bounded_der_length_kind
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> LowParse.Spec.Base.parser_kind
{ "end_col": 51, "end_line": 274, "start_col": 2, "start_line": 272 }
Prims.Tot
val parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t) : Tot bool
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max
val parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t) : Tot bool let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t) : Tot bool =
false
null
false
let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt8.t", "Prims.op_AmpAmp", "LowParse.Spec.DER.der_length_payload_size", "Prims.nat", "LowParse.Spec.DER.der_length_payload_size_of_tag", "Prims.bool" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t) : Tot bool
[]
LowParse.Spec.DER.parse_bounded_der_length_tag_cond
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> x: FStar.UInt8.t -> Prims.bool
{ "end_col": 120, "end_line": 245, "start_col": 1, "start_line": 245 }
Prims.Tot
val parse_der_length_weak_kind:parser_kind
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak
val parse_der_length_weak_kind:parser_kind let parse_der_length_weak_kind:parser_kind =
false
null
false
and_then_kind parse_u8_kind parse_der_length_payload_kind_weak
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.DER.parse_der_length_payload_kind_weak" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None
false
true
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_der_length_weak_kind:parser_kind
[]
LowParse.Spec.DER.parse_der_length_weak_kind
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser_kind
{ "end_col": 109, "end_line": 218, "start_col": 47, "start_line": 218 }
Prims.Tot
val der_length_max_eq : squash (der_length_max == pow2 (8 * 126) - 1)
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1)
val der_length_max_eq : squash (der_length_max == pow2 (8 * 126) - 1) let der_length_max_eq =
false
null
true
assert_norm (der_length_max == pow2 (8 * 126) - 1)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "LowParse.Spec.DER.der_length_max", "Prims.op_Subtraction", "Prims.pow2", "FStar.Mul.op_Star" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`())))
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val der_length_max_eq : squash (der_length_max == pow2 (8 * 126) - 1)
[]
LowParse.Spec.DER.der_length_max_eq
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Prims.squash (LowParse.Spec.DER.der_length_max == Prims.pow2 (8 * 126) - 1)
{ "end_col": 52, "end_line": 19, "start_col": 2, "start_line": 19 }
FStar.Pervasives.Lemma
val synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))]
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' )
val synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] =
false
null
true
synth_injective_intro' (synth_be_int len) (fun (x: Seq.lseq byte len) (x': Seq.lseq byte len) -> E.be_to_n_inj x x')
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.Combinators.synth_injective_intro'", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.DER.lint", "LowParse.Spec.DER.synth_be_int", "FStar.Endianness.be_to_n_inj", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))]
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))]
[]
LowParse.Spec.DER.synth_be_int_injective
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
len: Prims.nat -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.DER.synth_be_int len)) [SMTPat (LowParse.Spec.Combinators.synth_injective (LowParse.Spec.DER.synth_be_int len))]
{ "end_col": 3, "end_line": 73, "start_col": 2, "start_line": 71 }
Prims.Tot
val synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b
val synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) =
false
null
false
E.lemma_be_to_n_is_bounded b; E.be_to_n b
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "Prims.nat", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "FStar.Endianness.be_to_n", "Prims.unit", "FStar.Endianness.lemma_be_to_n_is_bounded", "LowParse.Spec.DER.lint" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len)
[]
LowParse.Spec.DER.synth_be_int
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
len: Prims.nat -> b: FStar.Seq.Properties.lseq LowParse.Bytes.byte len -> LowParse.Spec.DER.lint len
{ "end_col": 13, "end_line": 63, "start_col": 2, "start_line": 62 }
Prims.Tot
val parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None
val parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind =
false
null
false
[@@ inline_let ]let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.strong_parser_kind", "LowParse.Spec.DER.der_length_payload_size", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.parser_kind_metadata_some", "Prims.unit", "LowParse.Spec.DER.der_length_payload_size_le", "LowParse.Spec.Base.parser_kind" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t{min <= max}) : Tot parser_kind
[]
LowParse.Spec.DER.parse_bounded_der_length_payload_kind
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> LowParse.Spec.Base.parser_kind
{ "end_col": 85, "end_line": 232, "start_col": 2, "start_line": 231 }
Prims.Tot
val parse_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x
val parse_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) =
false
null
false
(parse_der_length_payload x) `parse_synth` (synth_der_length_payload32 x)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_payload_size_of_tag", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "FStar.UInt32.t", "LowParse.Spec.DER.tag_of_der_length32", "LowParse.Spec.DER.parse_der_length_payload", "LowParse.Spec.DER.synth_der_length_payload32", "LowParse.Spec.Base.parser" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x))
[]
LowParse.Spec.DER.parse_der_length_payload32
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4} -> LowParse.Spec.Base.parser (LowParse.Spec.DER.parse_der_length_payload_kind x) (LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length32 x)
{ "end_col": 71, "end_line": 827, "start_col": 2, "start_line": 827 }
Prims.Tot
val serialize_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length min max))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max)
val serialize_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length min max)) let serialize_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length min max)) =
false
null
false
Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Base.serialize_ext", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.DER.parse_der_length_weak_kind", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.parse_bounded_der_length_weak", "LowParse.Spec.DER.serialize_bounded_der_length_weak", "LowParse.Spec.DER.parse_bounded_der_length_kind", "LowParse.Spec.DER.parse_bounded_der_length", "Prims.unit", "FStar.Classical.forall_intro", "LowParse.Bytes.bytes", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.DER.parse_bounded_der_length_eq", "LowParse.Spec.Base.serializer" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max })
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length min max))
[]
LowParse.Spec.DER.serialize_bounded_der_length
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> LowParse.Spec.Base.serializer (LowParse.Spec.DER.parse_bounded_der_length min max)
{ "end_col": 38, "end_line": 715, "start_col": 2, "start_line": 711 }
Prims.Tot
val tag_of_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) (x: bounded_int min max) : Tot (y: U8.t{parse_bounded_der_length_tag_cond min max y == true})
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x
val tag_of_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) (x: bounded_int min max) : Tot (y: U8.t{parse_bounded_der_length_tag_cond min max y == true}) let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) (x: bounded_int min max) : Tot (y: U8.t{parse_bounded_der_length_tag_cond min max y == true}) =
false
null
false
[@@ inline_let ]let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.tag_of_der_length", "Prims.unit", "LowParse.Spec.DER.der_length_payload_size_le", "FStar.UInt8.t", "Prims.eq2", "Prims.bool", "LowParse.Spec.DER.parse_bounded_der_length_tag_cond" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tag_of_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) (x: bounded_int min max) : Tot (y: U8.t{parse_bounded_der_length_tag_cond min max y == true})
[]
LowParse.Spec.DER.tag_of_bounded_der_length
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> x: LowParse.Spec.DER.bounded_int min max -> y: FStar.UInt8.t{LowParse.Spec.DER.parse_bounded_der_length_tag_cond min max y == true}
{ "end_col": 21, "end_line": 255, "start_col": 2, "start_line": 253 }
Prims.Tot
val parse_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max)
val parse_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) let parse_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) =
false
null
false
parse_tagged_union (parse_u8 `parse_filter` (parse_bounded_der_length_tag_cond min max)) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Combinators.parse_tagged_union", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Combinators.parse_filter_refine", "FStar.UInt8.t", "LowParse.Spec.DER.parse_bounded_der_length_tag_cond", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.tag_of_bounded_der_length", "LowParse.Spec.DER.parse_bounded_der_length_payload_kind", "LowParse.Spec.DER.parse_bounded_der_length_payload", "LowParse.Spec.Base.parser", "LowParse.Spec.DER.parse_bounded_der_length_kind" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max })
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max))
[]
LowParse.Spec.DER.parse_bounded_der_length
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> LowParse.Spec.Base.parser (LowParse.Spec.DER.parse_bounded_der_length_kind min max) (LowParse.Spec.DER.bounded_int min max)
{ "end_col": 46, "end_line": 283, "start_col": 2, "start_line": 280 }
FStar.Pervasives.Lemma
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y)
let tag_of_der_length_eq_129_eta (x: U8.t{U8.v x == 129}) =
false
null
true
fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "FStar.UInt8.t", "Prims.eq2", "Prims.int", "FStar.UInt8.v", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.tag_of_der_length_eq_129", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.DER.synth_der_length_129", "LowParse.Spec.DER.synth_der_length_129_recip", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tag_of_der_length_eq_129_eta : x: FStar.UInt8.t{FStar.UInt8.v x == 129} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> FStar.Pervasives.Lemma (ensures LowParse.Spec.DER.synth_der_length_129 x (LowParse.Spec.DER.synth_der_length_129_recip x y) == y)
[]
LowParse.Spec.DER.tag_of_der_length_eq_129_eta
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{FStar.UInt8.v x == 129} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> FStar.Pervasives.Lemma (ensures LowParse.Spec.DER.synth_der_length_129 x (LowParse.Spec.DER.synth_der_length_129_recip x y) == y)
{ "end_col": 148, "end_line": 532, "start_col": 2, "start_line": 532 }
Prims.Tot
val parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max))
val parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) =
false
null
false
(parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) `parse_synth` (fun (y: der_length_t{min <= y && y <= max}) -> (y <: bounded_int min max))
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.DER.parse_der_length_weak_kind", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.op_AmpAmp", "Prims.bool", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.DER.parse_der_length_weak", "LowParse.Spec.Base.parser" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max })
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max))
[]
LowParse.Spec.DER.parse_bounded_der_length_weak
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> LowParse.Spec.Base.parser (LowParse.Spec.Combinators.parse_filter_kind LowParse.Spec.DER.parse_der_length_weak_kind ) (LowParse.Spec.DER.bounded_int min max)
{ "end_col": 94, "end_line": 372, "start_col": 2, "start_line": 370 }
Prims.GTot
val synth_der_length_129_recip (x: U8.t{x == 129uy}) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t{U8.v y >= 128})
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y
val synth_der_length_129_recip (x: U8.t{x == 129uy}) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t{U8.v y >= 128}) let synth_der_length_129_recip (x: U8.t{x == 129uy}) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t{U8.v y >= 128}) =
false
null
false
tag_of_der_length_eq_129 y; U8.uint_to_t y
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "sometrivial" ]
[ "FStar.UInt8.t", "Prims.eq2", "FStar.UInt8.__uint_to_t", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "FStar.UInt8.uint_to_t", "Prims.unit", "LowParse.Spec.DER.tag_of_der_length_eq_129", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt8.v" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_der_length_129_recip (x: U8.t{x == 129uy}) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t{U8.v y >= 128})
[]
LowParse.Spec.DER.synth_der_length_129_recip
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{x == 129uy} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> Prims.GTot (y: FStar.UInt8.t{FStar.UInt8.v y >= 128})
{ "end_col": 16, "end_line": 467, "start_col": 2, "start_line": 466 }
FStar.Pervasives.Lemma
val log256_le (x1 x2: nat) : Lemma (requires (0 < x1 /\ x1 <= x2)) (ensures (log256 x1 <= log256 x2))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2)
val log256_le (x1 x2: nat) : Lemma (requires (0 < x1 /\ x1 <= x2)) (ensures (log256 x1 <= log256 x2)) let log256_le x1 x2 =
false
null
true
Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "LowParse.Spec.DER.log256", "Prims.unit" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val log256_le (x1 x2: nat) : Lemma (requires (0 < x1 /\ x1 <= x2)) (ensures (log256 x1 <= log256 x2))
[]
LowParse.Spec.DER.log256_le
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x1: Prims.nat -> x2: Prims.nat -> FStar.Pervasives.Lemma (requires 0 < x1 /\ x1 <= x2) (ensures LowParse.Spec.DER.log256 x1 <= LowParse.Spec.DER.log256 x2)
{ "end_col": 58, "end_line": 43, "start_col": 2, "start_line": 43 }
FStar.Pervasives.Lemma
val parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end
val parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) =
false
null
true
parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload", "Prims.op_AmpAmp", "LowParse.Spec.DER.der_length_payload_size_le", "Prims.unit", "Prims.bool", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "LowParse.Spec.DER.parse_bounded_der_length_weak_unfold", "LowParse.Spec.DER.parse_bounded_der_length_unfold", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.parse_bounded_der_length", "LowParse.Spec.DER.parse_bounded_der_length_weak", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input))
[]
LowParse.Spec.DER.parse_bounded_der_length_eq
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length min max) input == LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length_weak min max) input)
{ "end_col": 9, "end_line": 422, "start_col": 2, "start_line": 410 }
Prims.Tot
val serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length_weak min max))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) ()
val serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length_weak min max)) let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length_weak min max)) =
false
null
false
serialize_synth _ (fun (y: der_length_t{min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max)) (fun (y: bounded_int min max) -> (y <: (y: der_length_t{min <= y && y <= max}))) ()
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.DER.parse_der_length_weak_kind", "Prims.op_AmpAmp", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.DER.parse_der_length_weak", "Prims.bool", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.DER.serialize_der_length_weak", "LowParse.Spec.Base.serializer", "LowParse.Spec.DER.parse_bounded_der_length_weak" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max })
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t{min <= max}) : Tot (serializer (parse_bounded_der_length_weak min max))
[]
LowParse.Spec.DER.serialize_bounded_der_length_weak
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> LowParse.Spec.Base.serializer (LowParse.Spec.DER.parse_bounded_der_length_weak min max)
{ "end_col": 6, "end_line": 705, "start_col": 2, "start_line": 697 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () )
let serialize_der_length_payload_greater (x: U8.t{not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy)}) (len: nat{len == U8.v x - 128}) =
false
null
false
(serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) ()) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater_recip x len) ())
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.op_Equality", "FStar.UInt8.__uint_to_t", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Subtraction", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Base.total_constant_size_parser_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.DER.lint", "Prims.op_GreaterThanOrEqual", "Prims.pow2", "FStar.Mul.op_Star", "Prims.bool", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Combinators.parse_synth", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.SeqBytes.Base.parse_seq_flbytes", "LowParse.Spec.DER.synth_be_int", "LowParse.Spec.DER.synth_der_length_greater", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.SeqBytes.Base.serialize_seq_flbytes", "LowParse.Spec.DER.synth_be_int_recip", "LowParse.Spec.DER.synth_der_length_greater_recip", "LowParse.Spec.Base.serializer" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_der_length_payload_greater : x: FStar.UInt8.t {Prims.op_Negation (FStar.UInt8.v x < 128 || x = 128uy || x = 255uy || x = 129uy)} -> len: Prims.nat{len == FStar.UInt8.v x - 128} -> LowParse.Spec.Base.serializer (LowParse.Spec.Combinators.parse_synth (LowParse.Spec.Combinators.parse_filter (LowParse.Spec.Combinators.parse_synth (LowParse.Spec.SeqBytes.Base.parse_seq_flbytes len ) (LowParse.Spec.DER.synth_be_int len)) (fun y -> y >= Prims.pow2 (8 * (len - 1)))) (LowParse.Spec.DER.synth_der_length_greater x len))
[]
LowParse.Spec.DER.serialize_der_length_payload_greater
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t {Prims.op_Negation (FStar.UInt8.v x < 128 || x = 128uy || x = 255uy || x = 129uy)} -> len: Prims.nat{len == FStar.UInt8.v x - 128} -> LowParse.Spec.Base.serializer (LowParse.Spec.Combinators.parse_synth (LowParse.Spec.Combinators.parse_filter (LowParse.Spec.Combinators.parse_synth (LowParse.Spec.SeqBytes.Base.parse_seq_flbytes len ) (LowParse.Spec.DER.synth_be_int len)) (fun y -> y >= Prims.pow2 (8 * (len - 1)))) (LowParse.Spec.DER.synth_der_length_greater x len))
{ "end_col": 7, "end_line": 523, "start_col": 6, "start_line": 502 }
FStar.Pervasives.Lemma
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y)
let tag_of_der_length_lt_128_eta (x: U8.t{U8.v x < 128}) =
false
null
true
fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt8.v", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.tag_of_der_length_lt_128", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt8.n", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tag_of_der_length_lt_128_eta : x: FStar.UInt8.t{FStar.UInt8.v x < 128} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> FStar.Pervasives.Lemma (ensures FStar.UInt8.v x == y)
[]
LowParse.Spec.DER.tag_of_der_length_lt_128_eta
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{FStar.UInt8.v x < 128} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> FStar.Pervasives.Lemma (ensures FStar.UInt8.v x == y)
{ "end_col": 99, "end_line": 526, "start_col": 2, "start_line": 526 }
FStar.Pervasives.Lemma
val log256_unique (x: nat) (y: nat) : Lemma (requires ( x > 0 /\ y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y) )) (ensures (y == log256 x))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y)
val log256_unique (x: nat) (y: nat) : Lemma (requires ( x > 0 /\ y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y) )) (ensures (y == log256 x)) let log256_unique x y =
false
null
true
Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "LowParse.Spec.DER.log256", "Prims.unit" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val log256_unique (x: nat) (y: nat) : Lemma (requires ( x > 0 /\ y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y) )) (ensures (y == log256 x))
[]
LowParse.Spec.DER.log256_unique
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: Prims.nat -> y: Prims.nat -> FStar.Pervasives.Lemma (requires x > 0 /\ y > 0 /\ Prims.pow2 (8 * (y - 1)) <= x /\ x < Prims.pow2 (8 * y)) (ensures y == LowParse.Spec.DER.log256 x)
{ "end_col": 49, "end_line": 38, "start_col": 2, "start_line": 37 }
Prims.Tot
val serialize_der_length_weak:serializer parse_der_length_weak
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x))
val serialize_der_length_weak:serializer parse_der_length_weak let serialize_der_length_weak:serializer parse_der_length_weak =
false
null
false
serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x))
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.serialize_tagged_union", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.Int.serialize_u8", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload_kind_weak", "LowParse.Spec.Base.weaken", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.parse_der_length_payload", "LowParse.Spec.Base.parser", "LowParse.Spec.Combinators.serialize_weaken", "LowParse.Spec.DER.serialize_der_length_payload", "LowParse.Spec.Base.serializer" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end
false
true
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_der_length_weak:serializer parse_der_length_weak
[]
LowParse.Spec.DER.serialize_der_length_weak
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.serializer LowParse.Spec.DER.parse_der_length_weak
{ "end_col": 99, "end_line": 573, "start_col": 2, "start_line": 570 }
Prims.Tot
val parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)))
val parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) =
false
null
false
weaken (parse_bounded_der_length_payload_kind min max) (((parse_der_length_payload x) `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x {min <= y && y <= max}) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)))
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt8.t", "Prims.eq2", "Prims.bool", "LowParse.Spec.DER.parse_bounded_der_length_tag_cond", "LowParse.Spec.Base.weaken", "LowParse.Spec.DER.parse_bounded_der_length_payload_kind", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Base.refine_with_tag", "Prims.l_or", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.tag_of_bounded_der_length", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.DER.tag_of_der_length", "Prims.op_AmpAmp", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.DER.parse_der_length_payload", "LowParse.Spec.Base.parser" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x))
[]
LowParse.Spec.DER.parse_bounded_der_length_payload
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> x: FStar.UInt8.t{LowParse.Spec.DER.parse_bounded_der_length_tag_cond min max x == true} -> LowParse.Spec.Base.parser (LowParse.Spec.DER.parse_bounded_der_length_payload_kind min max) (LowParse.Spec.Base.refine_with_tag (LowParse.Spec.DER.tag_of_bounded_der_length min max) x)
{ "end_col": 156, "end_line": 265, "start_col": 2, "start_line": 262 }
Prims.GTot
val synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int32 min max) : GTot (bounded_int min max)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int32 min max) : GTot (bounded_int min max) = U32.v x
val synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int32 min max) : GTot (bounded_int min max) let synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int32 min max) : GTot (bounded_int min max) =
false
null
false
U32.v x
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "sometrivial" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.bounded_int32", "FStar.UInt32.v", "LowParse.Spec.DER.bounded_int" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq x = log256_unique x (log256' x) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max) : Tot (bounded_int32 min max) = U32.uint_to_t x let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) = parse_bounded_der_length min max `parse_synth` synth_bounded_der_length32 min max #push-options "--z3rlimit 50" let parse_bounded_der_length32_unfold min max input = parse_synth_eq (parse_bounded_der_length min max) (synth_bounded_der_length32 min max) input; parse_bounded_der_length_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in assert_norm (4294967296 <= der_length_max); der_length_payload_size_le max 4294967295; assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); log256_unique 4294967295 4; parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input' ; match parse (parse_der_length_payload x) input' with | None -> () | Some (y, _) -> if y >= 128 then begin assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end else () #pop-options let synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int32 min max)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int32 min max) : GTot (bounded_int min max)
[]
LowParse.Spec.DER.synth_bounded_der_length32_recip
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max /\ max < 4294967296} -> x: LowParse.Spec.BoundedInt.bounded_int32 min max -> Prims.GTot (LowParse.Spec.DER.bounded_int min max)
{ "end_col": 9, "end_line": 970, "start_col": 2, "start_line": 970 }
FStar.Pervasives.Lemma
val be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))]
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296)
val be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] =
false
null
true
integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.BoundedInt.integer_size", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.pow2", "FStar.Mul.op_Star", "Prims.unit", "LowParse.Spec.BoundedInt.integer_size_values", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.DER.be_int_of_bounded_integer", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len))
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))]
[]
LowParse.Spec.DER.be_int_of_bounded_integer_injective
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
len: LowParse.Spec.BoundedInt.integer_size -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.DER.be_int_of_bounded_integer len)) [ SMTPat (LowParse.Spec.Combinators.synth_injective (LowParse.Spec.DER.be_int_of_bounded_integer len)) ]
{ "end_col": 42, "end_line": 849, "start_col": 2, "start_line": 845 }
Prims.Tot
val log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)})
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end
val log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) let rec log256 (x: nat{x > 0}) : Tot (y: nat{y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) =
false
null
false
assert_norm (pow2 8 == 256); if x < 256 then 1 else let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.bool", "Prims.op_Addition", "Prims.unit", "FStar.Math.Lemmas.pow2_plus", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.pow2", "Prims.op_Multiply", "Prims.op_Division", "LowParse.Spec.DER.log256", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 })
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)})
[ "recursion" ]
LowParse.Spec.DER.log256
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: Prims.nat{x > 0} -> y: Prims.nat{y > 0 /\ Prims.pow2 (8 * (y - 1)) <= x /\ x < Prims.pow2 (8 * y)}
{ "end_col": 5, "end_line": 32, "start_col": 2, "start_line": 24 }
Prims.Tot
val parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) = parse_bounded_der_length min max `parse_synth` synth_bounded_der_length32 min max
val parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) =
false
null
false
(parse_bounded_der_length min max) `parse_synth` (synth_bounded_der_length32 min max)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.DER.parse_bounded_der_length_kind", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.DER.parse_bounded_der_length", "LowParse.Spec.DER.synth_bounded_der_length32", "LowParse.Spec.Base.parser", "LowParse.Spec.DER.parse_bounded_der_length32_kind" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq x = log256_unique x (log256' x) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max) : Tot (bounded_int32 min max) = U32.uint_to_t x let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 })
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max))
[]
LowParse.Spec.DER.parse_bounded_der_length32
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max /\ max < 4294967296} -> LowParse.Spec.Base.parser (LowParse.Spec.DER.parse_bounded_der_length32_kind min max) (LowParse.Spec.BoundedInt.bounded_int32 min max)
{ "end_col": 83, "end_line": 933, "start_col": 2, "start_line": 933 }
Prims.GTot
val be_int_of_bounded_integer (len: integer_size) (x: nat{x < pow2 (8 * len)}) : GTot (bounded_integer len)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x
val be_int_of_bounded_integer (len: integer_size) (x: nat{x < pow2 (8 * len)}) : GTot (bounded_integer len) let be_int_of_bounded_integer (len: integer_size) (x: nat{x < pow2 (8 * len)}) : GTot (bounded_integer len) =
false
null
false
integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "sometrivial" ]
[ "LowParse.Spec.BoundedInt.integer_size", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Mul.op_Star", "FStar.UInt32.uint_to_t", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "LowParse.Spec.BoundedInt.integer_size_values", "LowParse.Spec.BoundedInt.bounded_integer" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val be_int_of_bounded_integer (len: integer_size) (x: nat{x < pow2 (8 * len)}) : GTot (bounded_integer len)
[]
LowParse.Spec.DER.be_int_of_bounded_integer
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
len: LowParse.Spec.BoundedInt.integer_size -> x: Prims.nat{x < Prims.pow2 (8 * len)} -> Prims.GTot (LowParse.Spec.BoundedInt.bounded_integer len)
{ "end_col": 17, "end_line": 838, "start_col": 2, "start_line": 833 }
FStar.Pervasives.Lemma
val parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else ()
val parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None)) let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None)) =
false
null
true
parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t{parse_bounded_der_length_tag_cond min max x == true})) input'
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.Base.consumed_length", "Prims.op_AmpAmp", "LowParse.Spec.DER.der_length_payload_size", "LowParse.Spec.DER.parse_bounded_der_length_payload_unfold", "Prims.eq2", "Prims.bool", "LowParse.Spec.DER.parse_bounded_der_length_tag_cond", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.unit", "Prims.nat", "LowParse.Spec.DER.der_length_payload_size_of_tag", "LowParse.Spec.DER.parse_bounded_der_length_unfold_aux", "Prims.l_True", "Prims.squash", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.parse_bounded_der_length", "FStar.Pervasives.Native.None", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None))
[]
LowParse.Spec.DER.parse_bounded_der_length_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length min max) input == (match LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u8 input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> let len = LowParse.Spec.DER.der_length_payload_size_of_tag x in (match LowParse.Spec.DER.der_length_payload_size min <= len && len <= LowParse.Spec.DER.der_length_payload_size max with | true -> let input' = FStar.Seq.Base.slice input consumed_x (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_der_length_payload x) input' with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed_y) -> (match min <= y && y <= max with | true -> FStar.Pervasives.Native.Some (y, consumed_x + consumed_y) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.DER.bounded_int min max * LowParse.Spec.Base.consumed_length input)) <: FStar.Pervasives.Native.option (LowParse.Spec.DER.bounded_int min max * LowParse.Spec.Base.consumed_length input) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.DER.bounded_int min max * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 11, "end_line": 364, "start_col": 2, "start_line": 355 }
FStar.Pervasives.Lemma
val parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) (input': bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == (match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input'
val parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) (input': bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == (match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None)) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) (input': bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == (match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None)) =
false
null
true
parse_synth_eq ((parse_der_length_payload x) `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x {min <= y && y <= max}) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input'; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input'
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt8.t", "Prims.eq2", "Prims.bool", "LowParse.Spec.DER.parse_bounded_der_length_tag_cond", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_filter_eq", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload", "Prims.op_AmpAmp", "Prims.unit", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.l_or", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.tag_of_bounded_der_length", "LowParse.Spec.Combinators.parse_filter", "Prims.l_True", "Prims.squash", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.DER.parse_bounded_der_length_payload", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None ))
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t{parse_bounded_der_length_tag_cond min max x == true}) (input': bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == (match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None))
[]
LowParse.Spec.DER.parse_bounded_der_length_payload_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> x: FStar.UInt8.t{LowParse.Spec.DER.parse_bounded_der_length_tag_cond min max x == true} -> input': LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length_payload min max x) input' == (match LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_der_length_payload x) input' with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed_y) -> (match min <= y && y <= max with | true -> FStar.Pervasives.Native.Some (y, consumed_y) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.Base.refine_with_tag (LowParse.Spec.DER.tag_of_bounded_der_length min max) x * LowParse.Spec.Base.consumed_length input')))
{ "end_col": 16, "end_line": 310, "start_col": 6, "start_line": 302 }
FStar.Pervasives.Lemma
val parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input
val parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None)) let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None)) =
false
null
true
parse_tagged_union_eq (parse_u8 `parse_filter` (parse_bounded_der_length_tag_cond min max)) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_filter_eq", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.DER.parse_bounded_der_length_tag_cond", "Prims.unit", "LowParse.Spec.Combinators.parse_tagged_union_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.tag_of_bounded_der_length", "LowParse.Spec.DER.parse_bounded_der_length_payload_kind", "LowParse.Spec.DER.parse_bounded_der_length_payload", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.DER.parse_bounded_der_length", "FStar.Pervasives.Native.None", "Prims.op_AmpAmp", "LowParse.Spec.DER.der_length_payload_size", "LowParse.Spec.Base.refine_with_tag", "Prims.l_or", "Prims.bool", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.nat", "LowParse.Spec.DER.der_length_payload_size_of_tag", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None))
[]
LowParse.Spec.DER.parse_bounded_der_length_unfold_aux
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length min max) input == (match LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u8 input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> let len = LowParse.Spec.DER.der_length_payload_size_of_tag x in (match LowParse.Spec.DER.der_length_payload_size min <= len && len <= LowParse.Spec.DER.der_length_payload_size max with | true -> let input' = FStar.Seq.Base.slice input consumed_x (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length_payload min max x) input' with | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed_y) -> FStar.Pervasives.Native.Some (y, consumed_x + consumed_y) | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.DER.bounded_int min max * LowParse.Spec.Base.consumed_length input) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.DER.bounded_int min max * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 76, "end_line": 334, "start_col": 2, "start_line": 329 }
FStar.Pervasives.Lemma
val parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma (let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse (parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len)) input == parse (parse_bounded_integer len) input)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input
val parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma (let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse (parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len)) input == parse (parse_bounded_integer len) input) let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma (let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse (parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len)) input == parse (parse_bounded_integer len) input) =
false
null
true
let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq ((parse_seq_flbytes len) `parse_synth` (synth_be_int len)) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Bytes.bytes", "LowParse.Spec.BoundedInt.parse_bounded_integer_spec", "Prims.unit", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.DER.lint", "LowParse.Spec.SeqBytes.Base.parse_seq_flbytes", "LowParse.Spec.DER.synth_be_int", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Mul.op_Star", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.DER.be_int_of_bounded_integer", "LowParse.Spec.DER.be_int_of_bounded_integer_injective", "LowParse.Spec.DER.synth_be_int_injective", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma (let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse (parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len)) input == parse (parse_bounded_integer len) input)
[]
LowParse.Spec.DER.parse_seq_flbytes_synth_be_int_eq
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
len: LowParse.Spec.BoundedInt.integer_size -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures ([@@ FStar.Pervasives.inline_let ]let _ = LowParse.Spec.DER.synth_be_int_injective len in [@@ FStar.Pervasives.inline_let ]let _ = LowParse.Spec.DER.be_int_of_bounded_integer_injective len in LowParse.Spec.Base.parse (LowParse.Spec.Combinators.parse_synth (LowParse.Spec.Combinators.parse_synth (LowParse.Spec.SeqBytes.Base.parse_seq_flbytes len) (LowParse.Spec.DER.synth_be_int len)) (LowParse.Spec.DER.be_int_of_bounded_integer len)) input == LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer len) input))
{ "end_col": 40, "end_line": 874, "start_col": 1, "start_line": 868 }
FStar.Pervasives.Lemma
val parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input
val parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None)) =
false
null
true
parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t{min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_tagged_union_eq", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload_kind_weak", "LowParse.Spec.Base.weaken", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.parse_der_length_payload", "LowParse.Spec.Base.parser", "Prims.unit", "LowParse.Spec.Combinators.parse_filter_eq", "LowParse.Spec.DER.parse_der_length_weak_kind", "LowParse.Spec.DER.parse_der_length_weak", "Prims.op_AmpAmp", "Prims.bool", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.Combinators.parse_filter", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.DER.parse_bounded_der_length_weak", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_Addition", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t{min <= max}) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None))
[]
LowParse.Spec.DER.parse_bounded_der_length_weak_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length_weak min max) input == (match LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u8 input with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> let input' = FStar.Seq.Base.slice input consumed_x (FStar.Seq.Base.length input) in (match LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_der_length_payload x) input' with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed_y) -> (match min <= y && y <= max with | true -> FStar.Pervasives.Native.Some (y, consumed_x + consumed_y) | _ -> FStar.Pervasives.Native.None) <: FStar.Pervasives.Native.option (LowParse.Spec.DER.bounded_int min max * LowParse.Spec.Base.consumed_length input)) <: FStar.Pervasives.Native.option (LowParse.Spec.DER.bounded_int min max * LowParse.Spec.Base.consumed_length input)))
{ "end_col": 9, "end_line": 402, "start_col": 2, "start_line": 392 }
Prims.Tot
val serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (serializer (parse_bounded_der_length32 min max))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (serializer (parse_bounded_der_length32 min max)) = serialize_synth _ (synth_bounded_der_length32 min max) (serialize_bounded_der_length min max) (synth_bounded_der_length32_recip min max) ()
val serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (serializer (parse_bounded_der_length32 min max)) let serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) : Tot (serializer (parse_bounded_der_length32 min max)) =
false
null
false
serialize_synth _ (synth_bounded_der_length32 min max) (serialize_bounded_der_length min max) (synth_bounded_der_length32_recip min max) ()
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.DER.parse_bounded_der_length_kind", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.DER.parse_bounded_der_length", "LowParse.Spec.DER.synth_bounded_der_length32", "LowParse.Spec.DER.serialize_bounded_der_length", "LowParse.Spec.DER.synth_bounded_der_length32_recip", "LowParse.Spec.Base.serializer", "LowParse.Spec.DER.parse_bounded_der_length32_kind", "LowParse.Spec.DER.parse_bounded_der_length32" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq x = log256_unique x (log256' x) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max) : Tot (bounded_int32 min max) = U32.uint_to_t x let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) = parse_bounded_der_length min max `parse_synth` synth_bounded_der_length32 min max #push-options "--z3rlimit 50" let parse_bounded_der_length32_unfold min max input = parse_synth_eq (parse_bounded_der_length min max) (synth_bounded_der_length32 min max) input; parse_bounded_der_length_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in assert_norm (4294967296 <= der_length_max); der_length_payload_size_le max 4294967295; assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); log256_unique 4294967295 4; parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input' ; match parse (parse_der_length_payload x) input' with | None -> () | Some (y, _) -> if y >= 128 then begin assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end else () #pop-options let synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int32 min max) : GTot (bounded_int min max) = U32.v x let serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 })
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (serializer (parse_bounded_der_length32 min max))
[]
LowParse.Spec.DER.serialize_bounded_der_length32
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max /\ max < 4294967296} -> LowParse.Spec.Base.serializer (LowParse.Spec.DER.parse_bounded_der_length32 min max)
{ "end_col": 6, "end_line": 981, "start_col": 2, "start_line": 976 }
Prims.Tot
val parse_der_length_weak:parser parse_der_length_weak_kind der_length_t
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x))
val parse_der_length_weak:parser parse_der_length_weak_kind der_length_t let parse_der_length_weak:parser parse_der_length_weak_kind der_length_t =
false
null
false
parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x))
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.Combinators.parse_tagged_union", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload_kind_weak", "LowParse.Spec.Base.weaken", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.parse_der_length_payload", "LowParse.Spec.Base.parser" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak
false
true
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_der_length_weak:parser parse_der_length_weak_kind der_length_t
[]
LowParse.Spec.DER.parse_der_length_weak
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
LowParse.Spec.Base.parser LowParse.Spec.DER.parse_der_length_weak_kind LowParse.Spec.DER.der_length_t
{ "end_col": 85, "end_line": 224, "start_col": 2, "start_line": 221 }
FStar.Pervasives.Lemma
val der_length_payload_size_le (x1 x2: der_length_t) : Lemma (requires (x1 <= x2)) (ensures (der_length_payload_size x1 <= der_length_payload_size x2))
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126)
val der_length_payload_size_le (x1 x2: der_length_t) : Lemma (requires (x1 <= x2)) (ensures (der_length_payload_size x1 <= der_length_payload_size x2)) let der_length_payload_size_le x1 x2 =
false
null
true
if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.op_BarBar", "Prims.op_LessThan", "Prims.bool", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "LowParse.Spec.DER.der_length_max", "Prims.pow2", "LowParse.Spec.DER.log256_le", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Multiply", "LowParse.Spec.DER.log256" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val der_length_payload_size_le (x1 x2: der_length_t) : Lemma (requires (x1 <= x2)) (ensures (der_length_payload_size x1 <= der_length_payload_size x2))
[]
LowParse.Spec.DER.der_length_payload_size_le
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x1: LowParse.Spec.DER.der_length_t -> x2: LowParse.Spec.DER.der_length_t -> FStar.Pervasives.Lemma (requires x1 <= x2) (ensures LowParse.Spec.DER.der_length_payload_size x1 <= LowParse.Spec.DER.der_length_payload_size x2 )
{ "end_col": 53, "end_line": 56, "start_col": 2, "start_line": 48 }
FStar.Pervasives.Lemma
val tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126)
val tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) =
false
null
true
if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.op_LessThan", "Prims.bool", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "LowParse.Spec.DER.der_length_max", "Prims.pow2", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Multiply", "LowParse.Spec.DER.log256", "Prims.l_or", "FStar.UInt.uint_t", "FStar.UInt8.v", "LowParse.Spec.DER.tag_of_der_length", "Prims.squash", "Prims.l_False", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255))
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False)
[]
LowParse.Spec.DER.tag_of_der_length_invalid
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: LowParse.Spec.DER.der_length_t -> FStar.Pervasives.Lemma (requires (let y = FStar.UInt8.v (LowParse.Spec.DER.tag_of_der_length x) in y == 128 \/ y == 255)) (ensures Prims.l_False)
{ "end_col": 52, "end_line": 448, "start_col": 2, "start_line": 443 }
Prims.Tot
val synth_der_length_129 (x: U8.t{x == 129uy}) (y: U8.t{U8.v y >= 128}) : Tot (refine_with_tag tag_of_der_length x)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y
val synth_der_length_129 (x: U8.t{x == 129uy}) (y: U8.t{U8.v y >= 128}) : Tot (refine_with_tag tag_of_der_length x) let synth_der_length_129 (x: U8.t{x == 129uy}) (y: U8.t{U8.v y >= 128}) : Tot (refine_with_tag tag_of_der_length x) =
false
null
false
assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.eq2", "FStar.UInt8.__uint_to_t", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt8.v", "Prims.unit", "LowParse.Spec.DER.log256_unique", "Prims._assert", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.Pervasives.assert_norm", "Prims.op_LessThan", "Prims.int", "Prims.pow2", "Prims.op_Subtraction", "FStar.Mul.op_Star", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_der_length_129 (x: U8.t{x == 129uy}) (y: U8.t{U8.v y >= 128}) : Tot (refine_with_tag tag_of_der_length x)
[]
LowParse.Spec.DER.synth_der_length_129
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{x == 129uy} -> y: FStar.UInt8.t{FStar.UInt8.v y >= 128} -> LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x
{ "end_col": 8, "end_line": 85, "start_col": 2, "start_line": 79 }
FStar.Pervasives.Lemma
val tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126)
val tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) =
false
null
true
if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.op_LessThan", "Prims.bool", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "LowParse.Spec.DER.der_length_max", "Prims.pow2", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Multiply", "LowParse.Spec.DER.log256", "FStar.UInt8.v", "LowParse.Spec.DER.tag_of_der_length", "Prims.squash", "Prims.op_GreaterThanOrEqual", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129))
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256))
[]
LowParse.Spec.DER.tag_of_der_length_eq_129
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: LowParse.Spec.DER.der_length_t -> FStar.Pervasives.Lemma (requires FStar.UInt8.v (LowParse.Spec.DER.tag_of_der_length x) == 129) (ensures x >= 128 /\ x < 256)
{ "end_col": 52, "end_line": 460, "start_col": 2, "start_line": 455 }
Prims.GTot
val synth_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4}) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y
val synth_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4}) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) let synth_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4}) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) =
false
null
false
let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then (Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y)) in U32.uint_to_t y
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "sometrivial" ]
[ "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_payload_size_of_tag", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "FStar.UInt32.uint_to_t", "Prims.unit", "Prims.op_GreaterThanOrEqual", "Prims._assert", "Prims.eq2", "Prims.int", "FStar.UInt8.v", "Prims.op_Addition", "LowParse.Spec.DER.log256", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.bool", "FStar.Pervasives.assert_norm", "Prims.pow2", "LowParse.Spec.DER.der_length_max", "FStar.UInt32.t", "LowParse.Spec.DER.tag_of_der_length32" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_der_length_payload32 (x: U8.t{der_length_payload_size_of_tag x <= 4}) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x)
[]
LowParse.Spec.DER.synth_der_length_payload32
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> Prims.GTot (LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length32 x)
{ "end_col": 17, "end_line": 802, "start_col": 1, "start_line": 792 }
Prims.Tot
val synth_der_length_greater_recip (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x % 128}) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len {y >= pow2 (8 * (len - 1))})
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y
val synth_der_length_greater_recip (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x % 128}) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len {y >= pow2 (8 * (len - 1))}) let synth_der_length_greater_recip (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x % 128}) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len {y >= pow2 (8 * (len - 1))}) =
false
null
false
assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "FStar.UInt8.v", "Prims.op_LessThan", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "Prims.unit", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "LowParse.Spec.DER.log256", "FStar.Pervasives.assert_norm", "LowParse.Spec.DER.der_length_max", "Prims.pow2", "LowParse.Spec.DER.lint", "Prims.op_GreaterThanOrEqual" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_der_length_greater_recip (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x % 128}) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len {y >= pow2 (8 * (len - 1))})
[]
LowParse.Spec.DER.synth_der_length_greater_recip
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{FStar.UInt8.v x > 129 /\ FStar.UInt8.v x < 255} -> len: Prims.nat{len == FStar.UInt8.v x % 128} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> y: LowParse.Spec.DER.lint len {y >= Prims.pow2 (8 * (len - 1))}
{ "end_col": 3, "end_line": 488, "start_col": 2, "start_line": 486 }
Prims.Tot
val synth_der_length_greater (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x - 128}) (y: lint len {y >= pow2 (8 * (len - 1))}) : Tot (refine_with_tag tag_of_der_length x)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y
val synth_der_length_greater (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x - 128}) (y: lint len {y >= pow2 (8 * (len - 1))}) : Tot (refine_with_tag tag_of_der_length x) let synth_der_length_greater (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x - 128}) (y: lint len {y >= pow2 (8 * (len - 1))}) : Tot (refine_with_tag tag_of_der_length x) =
false
null
false
assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "FStar.UInt8.v", "Prims.op_LessThan", "Prims.nat", "Prims.eq2", "Prims.int", "Prims.op_Subtraction", "LowParse.Spec.DER.lint", "Prims.op_GreaterThanOrEqual", "Prims.pow2", "FStar.Mul.op_Star", "Prims.unit", "LowParse.Spec.DER.log256_unique", "FStar.Math.Lemmas.pow2_le_compat", "Prims._assert", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.Pervasives.assert_norm", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } )
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_der_length_greater (x: U8.t{U8.v x > 129 /\ U8.v x < 255}) (len: nat{len == U8.v x - 128}) (y: lint len {y >= pow2 (8 * (len - 1))}) : Tot (refine_with_tag tag_of_der_length x)
[]
LowParse.Spec.DER.synth_der_length_greater
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{FStar.UInt8.v x > 129 /\ FStar.UInt8.v x < 255} -> len: Prims.nat{len == FStar.UInt8.v x - 128} -> y: LowParse.Spec.DER.lint len {y >= Prims.pow2 (8 * (len - 1))} -> LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x
{ "end_col": 3, "end_line": 100, "start_col": 2, "start_line": 92 }
FStar.Pervasives.Lemma
val synth_der_length_payload32_injective (x: U8.t{der_length_payload_size_of_tag x <= 4}) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))]
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end )
val synth_der_length_payload32_injective (x: U8.t{der_length_payload_size_of_tag x <= 4}) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] let synth_der_length_payload32_injective (x: U8.t{der_length_payload_size_of_tag x <= 4}) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] =
false
null
true
assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1: refine_with_tag tag_of_der_length x) (y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then (Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1)); if y2 >= 128 then (Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2)))
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_payload_size_of_tag", "LowParse.Spec.Combinators.synth_injective_intro'", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "FStar.UInt32.t", "LowParse.Spec.DER.tag_of_der_length32", "LowParse.Spec.DER.synth_der_length_payload32", "Prims.op_GreaterThanOrEqual", "Prims._assert", "Prims.eq2", "Prims.int", "FStar.UInt8.v", "Prims.op_Addition", "LowParse.Spec.DER.log256", "Prims.unit", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.bool", "FStar.Pervasives.assert_norm", "Prims.pow2", "LowParse.Spec.DER.der_length_max", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x))
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_der_length_payload32_injective (x: U8.t{der_length_payload_size_of_tag x <= 4}) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))]
[]
LowParse.Spec.DER.synth_der_length_payload32_injective
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4} -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.DER.synth_der_length_payload32 x)) [ SMTPat (LowParse.Spec.Combinators.synth_injective (LowParse.Spec.DER.synth_der_length_payload32 x)) ]
{ "end_col": 3, "end_line": 822, "start_col": 2, "start_line": 809 }
FStar.Pervasives.Lemma
val der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures (tag_of_der_length x == (if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy)))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4
val der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures (tag_of_der_length x == (if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy))) let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures (tag_of_der_length x == (if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy))) =
false
null
true
if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.op_LessThan", "Prims.bool", "LowParse.Spec.DER.log256_unique", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.pow2", "FStar.Mul.op_Star", "LowParse.Math.pow2_lt_recip", "Prims.op_Subtraction", "LowParse.Spec.DER.der_length_max", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Multiply", "LowParse.Spec.DER.log256", "Prims.squash", "FStar.UInt8.t", "LowParse.Spec.DER.tag_of_der_length", "FStar.UInt8.uint_to_t", "FStar.UInt8.__uint_to_t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures (tag_of_der_length x == (if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy)))
[]
LowParse.Spec.DER.der_length_payload_size_of_tag_inv32
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: LowParse.Spec.DER.der_length_t -> FStar.Pervasives.Lemma (requires x < 4294967296) (ensures LowParse.Spec.DER.tag_of_der_length x == (match x < 128 with | true -> FStar.UInt8.uint_to_t x | _ -> (match x < 256 with | true -> 129uy | _ -> (match x < 65536 with | true -> 130uy | _ -> (match x < 16777216 with | true -> 131uy | _ -> 132uy) <: FStar.UInt8.t) <: FStar.UInt8.t) <: FStar.UInt8.t))
{ "end_col": 23, "end_line": 786, "start_col": 2, "start_line": 766 }
Prims.Tot
val serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end
val serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) =
false
null
false
assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let x':der_length_t = U8.v x in if x' < 128 then serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) else let len:nat = U8.v x - 128 in synth_be_int_injective len; serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.op_LessThan", "LowParse.Spec.Combinators.serialize_weaken", "LowParse.Spec.Combinators.parse_ret_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Combinators.parse_ret", "LowParse.Spec.Combinators.serialize_ret", "LowParse.Spec.DER.tag_of_der_length_lt_128_eta", "Prims.bool", "Prims.op_BarBar", "Prims.op_Equality", "FStar.UInt8.__uint_to_t", "LowParse.Spec.Combinators.fail_serializer", "LowParse.Spec.DER.tag_of_der_length_invalid_eta", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.op_GreaterThanOrEqual", "FStar.UInt8.v", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.DER.synth_der_length_129", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.Int.serialize_u8", "LowParse.Spec.DER.synth_der_length_129_recip", "LowParse.Spec.Combinators.synth_inverse_intro'", "Prims.b2t", "LowParse.Spec.DER.tag_of_der_length_eq_129_eta", "LowParse.Spec.Base.total_constant_size_parser_kind", "LowParse.Spec.DER.lint", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Subtraction", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.SeqBytes.Base.parse_seq_flbytes", "LowParse.Spec.DER.synth_be_int", "LowParse.Spec.DER.synth_der_length_greater", "LowParse.Spec.DER.serialize_der_length_payload_greater", "Prims.unit", "LowParse.Spec.DER.synth_be_int_injective", "Prims.nat", "LowParse.Spec.Base.serializer", "LowParse.Spec.DER.parse_der_length_payload", "Prims._assert", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x))
[]
LowParse.Spec.DER.serialize_der_length_payload
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> LowParse.Spec.Base.serializer (LowParse.Spec.DER.parse_der_length_payload x)
{ "end_col": 6, "end_line": 567, "start_col": 2, "start_line": 537 }
Prims.GTot
val synth_be_int_recip (len: nat) (x: lint len) : GTot (b : Seq.lseq byte len)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x
val synth_be_int_recip (len: nat) (x: lint len) : GTot (b : Seq.lseq byte len) let synth_be_int_recip (len: nat) (x: lint len) : GTot (b : Seq.lseq byte len) =
false
null
false
E.n_to_be len x
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "sometrivial" ]
[ "Prims.nat", "LowParse.Spec.DER.lint", "FStar.Endianness.n_to_be", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_be_int_recip (len: nat) (x: lint len) : GTot (b : Seq.lseq byte len)
[]
LowParse.Spec.DER.synth_be_int_recip
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
len: Prims.nat -> x: LowParse.Spec.DER.lint len -> Prims.GTot (FStar.Seq.Properties.lseq LowParse.Bytes.byte len)
{ "end_col": 17, "end_line": 473, "start_col": 2, "start_line": 473 }
FStar.Pervasives.Lemma
val serialize_bounded_der_length32_unfold (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (y': bounded_int32 min max) : Lemma ( let res = serialize (serialize_bounded_der_length32 min max) y' in let x = tag_of_der_length32_impl y' in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then U32.v y' <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (Cast.uint32_to_uint8 y')) else let len = log256' (U32.v y') in res `Seq.equal` (s1 `Seq.append` serialize (serialize_bounded_integer len) y') )
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_der_length32_unfold min max y' = serialize_synth_eq _ (synth_bounded_der_length32 min max) (serialize_bounded_der_length min max) (synth_bounded_der_length32_recip min max) () y'; serialize_bounded_der_length_unfold min max (U32.v y'); let x = tag_of_der_length32_impl y' in if x `U8.lt` 128uy then () else if x = 129uy then FStar.Math.Lemmas.small_modulo_lemma_1 (U32.v y') 256 else begin assert (x <> 128uy /\ x <> 255uy); let len = log256' (U32.v y') in log256_eq (U32.v y'); serialize_bounded_integer_spec len y' end
val serialize_bounded_der_length32_unfold (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (y': bounded_int32 min max) : Lemma ( let res = serialize (serialize_bounded_der_length32 min max) y' in let x = tag_of_der_length32_impl y' in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then U32.v y' <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (Cast.uint32_to_uint8 y')) else let len = log256' (U32.v y') in res `Seq.equal` (s1 `Seq.append` serialize (serialize_bounded_integer len) y') ) let serialize_bounded_der_length32_unfold min max y' =
false
null
true
serialize_synth_eq _ (synth_bounded_der_length32 min max) (serialize_bounded_der_length min max) (synth_bounded_der_length32_recip min max) () y'; serialize_bounded_der_length_unfold min max (U32.v y'); let x = tag_of_der_length32_impl y' in if x `U8.lt` 128uy then () else if x = 129uy then FStar.Math.Lemmas.small_modulo_lemma_1 (U32.v y') 256 else (assert (x <> 128uy /\ x <> 255uy); let len = log256' (U32.v y') in log256_eq (U32.v y'); serialize_bounded_integer_spec len y')
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.bounded_int32", "FStar.UInt8.lt", "FStar.UInt8.__uint_to_t", "Prims.bool", "Prims.op_Equality", "FStar.UInt8.t", "FStar.Math.Lemmas.small_modulo_lemma_1", "FStar.UInt32.v", "LowParse.Spec.BoundedInt.serialize_bounded_integer_spec", "Prims.unit", "LowParse.Spec.DER.log256_eq", "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.BoundedInt.log256'", "Prims._assert", "Prims.op_disEquality", "LowParse.Spec.DER.der_length_max", "Prims.eq2", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.tag_of_der_length32_impl", "LowParse.Spec.DER.serialize_bounded_der_length_unfold", "LowParse.Spec.Combinators.serialize_synth_eq", "LowParse.Spec.DER.parse_bounded_der_length_kind", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.parse_bounded_der_length", "LowParse.Spec.DER.synth_bounded_der_length32", "LowParse.Spec.DER.serialize_bounded_der_length", "LowParse.Spec.DER.synth_bounded_der_length32_recip" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq x = log256_unique x (log256' x) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max) : Tot (bounded_int32 min max) = U32.uint_to_t x let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) = parse_bounded_der_length min max `parse_synth` synth_bounded_der_length32 min max #push-options "--z3rlimit 50" let parse_bounded_der_length32_unfold min max input = parse_synth_eq (parse_bounded_der_length min max) (synth_bounded_der_length32 min max) input; parse_bounded_der_length_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in assert_norm (4294967296 <= der_length_max); der_length_payload_size_le max 4294967295; assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); log256_unique 4294967295 4; parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input' ; match parse (parse_der_length_payload x) input' with | None -> () | Some (y, _) -> if y >= 128 then begin assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end else () #pop-options let synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int32 min max) : GTot (bounded_int min max) = U32.v x let serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (serializer (parse_bounded_der_length32 min max)) = serialize_synth _ (synth_bounded_der_length32 min max) (serialize_bounded_der_length min max) (synth_bounded_der_length32_recip min max) () let serialize_bounded_der_length32_unfold
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_der_length32_unfold (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (y': bounded_int32 min max) : Lemma ( let res = serialize (serialize_bounded_der_length32 min max) y' in let x = tag_of_der_length32_impl y' in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then U32.v y' <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (Cast.uint32_to_uint8 y')) else let len = log256' (U32.v y') in res `Seq.equal` (s1 `Seq.append` serialize (serialize_bounded_integer len) y') )
[]
LowParse.Spec.DER.serialize_bounded_der_length32_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max /\ max < 4294967296} -> y': LowParse.Spec.BoundedInt.bounded_int32 min max -> FStar.Pervasives.Lemma (ensures (let res = LowParse.Spec.Base.serialize (LowParse.Spec.DER.serialize_bounded_der_length32 min max) y' in let x = LowParse.Spec.DER.tag_of_der_length32_impl y' in let s1 = FStar.Seq.Base.create 1 x in (match FStar.UInt8.lt x 128uy with | true -> FStar.Seq.Base.equal res s1 | _ -> (match x = 129uy with | true -> FStar.UInt32.v y' <= 255 /\ FStar.Seq.Base.equal res (FStar.Seq.Base.append s1 (FStar.Seq.Base.create 1 (FStar.Int.Cast.uint32_to_uint8 y'))) | _ -> let len = LowParse.Spec.BoundedInt.log256' (FStar.UInt32.v y') in FStar.Seq.Base.equal res (FStar.Seq.Base.append s1 (LowParse.Spec.Base.serialize (LowParse.Spec.BoundedInt.serialize_bounded_integer len) y'))) <: Type0) <: Type0))
{ "end_col": 7, "end_line": 1003, "start_col": 2, "start_line": 985 }
Prims.Tot
val parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end
val parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) =
false
null
false
assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let x':der_length_t = U8.v x in if x' < 128 then weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` (synth_der_length_129 x) ) else let len:nat = U8.v x - 128 in synth_be_int_injective len; weaken (parse_der_length_payload_kind x) ((((parse_seq_flbytes len) `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` (synth_der_length_greater x len))
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "FStar.UInt8.t", "Prims.op_LessThan", "LowParse.Spec.Base.weaken", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.Combinators.parse_ret_kind", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.Combinators.parse_ret", "Prims.bool", "Prims.op_Equality", "FStar.UInt8.__uint_to_t", "LowParse.Spec.Combinators.fail_parser", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.op_GreaterThanOrEqual", "FStar.UInt8.v", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.DER.synth_der_length_129", "LowParse.Spec.Base.total_constant_size_parser_kind", "LowParse.Spec.DER.lint", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Subtraction", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.SeqBytes.Base.parse_seq_flbytes", "LowParse.Spec.DER.synth_be_int", "LowParse.Spec.DER.synth_der_length_greater", "Prims.unit", "LowParse.Spec.DER.synth_be_int_injective", "Prims.nat", "LowParse.Spec.Base.parser", "Prims._assert", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x))
[]
LowParse.Spec.DER.parse_der_length_payload
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> LowParse.Spec.Base.parser (LowParse.Spec.DER.parse_der_length_payload_kind x) (LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x)
{ "end_col": 5, "end_line": 133, "start_col": 2, "start_line": 105 }
FStar.Pervasives.Lemma
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False
let tag_of_der_length_invalid_eta (x: U8.t{U8.v x == 128 \/ U8.v x == 255}) =
false
null
true
fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "FStar.UInt8.t", "Prims.l_or", "Prims.eq2", "Prims.int", "FStar.UInt8.v", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.tag_of_der_length_invalid", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_False", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tag_of_der_length_invalid_eta : x: FStar.UInt8.t{FStar.UInt8.v x == 128 \/ FStar.UInt8.v x == 255} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> FStar.Pervasives.Lemma (ensures Prims.l_False)
[]
LowParse.Spec.DER.tag_of_der_length_invalid_eta
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{FStar.UInt8.v x == 128 \/ FStar.UInt8.v x == 255} -> y: LowParse.Spec.Base.refine_with_tag LowParse.Spec.DER.tag_of_der_length x -> FStar.Pervasives.Lemma (ensures Prims.l_False)
{ "end_col": 92, "end_line": 529, "start_col": 2, "start_line": 529 }
FStar.Pervasives.Lemma
val tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x)))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126)
val tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) =
false
null
true
if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.op_LessThan", "Prims.bool", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "LowParse.Spec.DER.der_length_max", "Prims.pow2", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Multiply", "LowParse.Spec.DER.log256", "FStar.UInt8.v", "LowParse.Spec.DER.tag_of_der_length", "Prims.squash", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt8.n", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128))
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x)))
[]
LowParse.Spec.DER.tag_of_der_length_lt_128
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: LowParse.Spec.DER.der_length_t -> FStar.Pervasives.Lemma (requires FStar.UInt8.v (LowParse.Spec.DER.tag_of_der_length x) < 128) (ensures x == FStar.UInt8.v (LowParse.Spec.DER.tag_of_der_length x))
{ "end_col": 52, "end_line": 436, "start_col": 2, "start_line": 431 }
FStar.Pervasives.Lemma
val parse_bounded_der_length32_unfold (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (input: bytes) : Lemma (let res = parse (parse_bounded_der_length32 min max) input in match parse parse_u8 input with | None -> res == None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in len <= 4 /\ ( match parse (parse_der_length_payload32 x) input' with | Some (y, consumed_y) -> if min <= U32.v y && U32.v y <= max then res == Some (y, consumed_x + consumed_y) else res == None | None -> res == None ) else res == None )
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_bounded_der_length32_unfold min max input = parse_synth_eq (parse_bounded_der_length min max) (synth_bounded_der_length32 min max) input; parse_bounded_der_length_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in assert_norm (4294967296 <= der_length_max); der_length_payload_size_le max 4294967295; assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); log256_unique 4294967295 4; parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input' ; match parse (parse_der_length_payload x) input' with | None -> () | Some (y, _) -> if y >= 128 then begin assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end else ()
val parse_bounded_der_length32_unfold (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (input: bytes) : Lemma (let res = parse (parse_bounded_der_length32 min max) input in match parse parse_u8 input with | None -> res == None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in len <= 4 /\ ( match parse (parse_der_length_payload32 x) input' with | Some (y, consumed_y) -> if min <= U32.v y && U32.v y <= max then res == Some (y, consumed_x + consumed_y) else res == None | None -> res == None ) else res == None ) let parse_bounded_der_length32_unfold min max input =
false
null
true
parse_synth_eq (parse_bounded_der_length min max) (synth_bounded_der_length32 min max) input; parse_bounded_der_length_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in assert_norm (4294967296 <= der_length_max); der_length_payload_size_le max 4294967295; assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); log256_unique 4294967295 4; parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input'; match parse (parse_der_length_payload x) input' with | None -> () | Some (y, _) -> if y >= 128 then (assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y))
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.Base.consumed_length", "Prims.op_AmpAmp", "LowParse.Spec.DER.der_length_payload_size", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload", "Prims.op_GreaterThanOrEqual", "Prims._assert", "Prims.eq2", "Prims.int", "FStar.UInt8.v", "Prims.op_Addition", "LowParse.Spec.DER.log256", "Prims.unit", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "FStar.Pervasives.assert_norm", "LowParse.Spec.DER.der_length_max", "Prims.pow2", "Prims.bool", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.DER.parse_der_length_payload_kind", "FStar.UInt32.t", "LowParse.Spec.DER.tag_of_der_length32", "LowParse.Spec.DER.synth_der_length_payload32", "LowParse.Spec.DER.log256_unique", "LowParse.Spec.DER.der_length_payload_size_le", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.nat", "LowParse.Spec.DER.der_length_payload_size_of_tag", "LowParse.Spec.DER.parse_bounded_der_length_unfold", "LowParse.Spec.DER.parse_bounded_der_length_kind", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.DER.parse_bounded_der_length", "LowParse.Spec.DER.synth_bounded_der_length32" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq x = log256_unique x (log256' x) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max) : Tot (bounded_int32 min max) = U32.uint_to_t x let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) = parse_bounded_der_length min max `parse_synth` synth_bounded_der_length32 min max #push-options "--z3rlimit 50" let parse_bounded_der_length32_unfold min max
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_bounded_der_length32_unfold (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (input: bytes) : Lemma (let res = parse (parse_bounded_der_length32 min max) input in match parse parse_u8 input with | None -> res == None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in len <= 4 /\ ( match parse (parse_der_length_payload32 x) input' with | Some (y, consumed_y) -> if min <= U32.v y && U32.v y <= max then res == Some (y, consumed_x + consumed_y) else res == None | None -> res == None ) else res == None )
[]
LowParse.Spec.DER.parse_bounded_der_length32_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max /\ max < 4294967296} -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures (let res = LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_bounded_der_length32 min max) input in (match LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u8 input with | FStar.Pervasives.Native.None #_ -> res == FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) -> let len = LowParse.Spec.DER.der_length_payload_size_of_tag x in (match LowParse.Spec.DER.der_length_payload_size min <= len && len <= LowParse.Spec.DER.der_length_payload_size max with | true -> let input' = FStar.Seq.Base.slice input consumed_x (FStar.Seq.Base.length input) in len <= 4 /\ (match LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_der_length_payload32 x) input' with | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y consumed_y) -> (match min <= FStar.UInt32.v y && FStar.UInt32.v y <= max with | true -> res == FStar.Pervasives.Native.Some (y, consumed_x + consumed_y) | _ -> res == FStar.Pervasives.Native.None) <: Prims.logical | FStar.Pervasives.Native.None #_ -> res == FStar.Pervasives.Native.None) | _ -> res == FStar.Pervasives.Native.None) <: Type0) <: Type0))
{ "end_col": 12, "end_line": 962, "start_col": 2, "start_line": 940 }
Prims.Tot
val synth_bounded_der_length32 (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int min max) : Tot (bounded_int32 min max)
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max) : Tot (bounded_int32 min max) = U32.uint_to_t x
val synth_bounded_der_length32 (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int min max) : Tot (bounded_int32 min max) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int min max) : Tot (bounded_int32 min max) =
false
null
false
U32.uint_to_t x
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.DER.bounded_int", "FStar.UInt32.uint_to_t", "LowParse.Spec.BoundedInt.bounded_int32" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq x = log256_unique x (log256' x) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val synth_bounded_der_length32 (min: der_length_t) (max: der_length_t{min <= max /\ max < 4294967296}) (x: bounded_int min max) : Tot (bounded_int32 min max)
[]
LowParse.Spec.DER.synth_bounded_der_length32
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max /\ max < 4294967296} -> x: LowParse.Spec.DER.bounded_int min max -> LowParse.Spec.BoundedInt.bounded_int32 min max
{ "end_col": 17, "end_line": 927, "start_col": 2, "start_line": 927 }
FStar.Pervasives.Lemma
val parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma (let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ (if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len:nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ (let res:option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ (if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None))))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end
val parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma (let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ (if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len:nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ (let res:option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ (if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None)))) let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma (let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ (if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len:nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ (let res:option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ (if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None)))) =
false
null
true
assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let x':der_length_t = U8.v x in if x' < 128 then () else if x = 128uy then () else if x = 255uy then () else if x = 129uy then (parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then log256_unique (U8.v y) 1) else let len:nat = U8.v x - 128 in synth_be_int_injective len; parse_synth_eq (((parse_seq_flbytes len) `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq ((parse_seq_flbytes len) `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res:option (lint len & consumed_length input) = parse ((parse_seq_flbytes len) `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then let y:y: lint len {y >= pow2 (8 * (len - 1))} = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "FStar.UInt8.t", "LowParse.Bytes.bytes", "Prims.op_LessThan", "Prims.bool", "Prims.op_Equality", "FStar.UInt8.__uint_to_t", "LowParse.Spec.Base.parse", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.Base.consumed_length", "Prims.op_GreaterThanOrEqual", "FStar.UInt8.v", "LowParse.Spec.DER.log256_unique", "Prims.unit", "LowParse.Spec.Combinators.parse_filter_eq", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.DER.synth_der_length_129", "LowParse.Spec.DER.lint", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Subtraction", "FStar.Math.Lemmas.pow2_le_compat", "Prims.b2t", "Prims.op_Multiply", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.SeqBytes.Base.parse_seq_flbytes", "LowParse.Spec.DER.synth_be_int", "Prims._assert", "Prims.op_GreaterThan", "LowParse.Spec.DER.synth_der_length_greater", "LowParse.Spec.DER.synth_be_int_injective", "Prims.nat", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.l_True", "Prims.squash", "Prims.l_and", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.op_BarBar", "FStar.Pervasives.Native.None", "Prims.logical", "LowParse.Spec.Combinators.synth_injective", "LowParse.Spec.DER.parse_der_length_payload", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma (let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ (if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len:nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ (let res:option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ (if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None))))
[]
LowParse.Spec.DER.parse_der_length_payload_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures (let y = LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_der_length_payload x) input in 256 < LowParse.Spec.DER.der_length_max /\ (match FStar.UInt8.v x < 128 with | true -> LowParse.Spec.DER.tag_of_der_length (FStar.UInt8.v x) == x /\ y == FStar.Pervasives.Native.Some (FStar.UInt8.v x, 0) | _ -> (match x = 128uy || x = 255uy with | true -> y == FStar.Pervasives.Native.None | _ -> (match x = 129uy with | true -> (match LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u8 input with | FStar.Pervasives.Native.None #_ -> y == FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ z consumed) -> (match FStar.UInt8.v z < 128 with | true -> y == FStar.Pervasives.Native.None | _ -> LowParse.Spec.DER.tag_of_der_length (FStar.UInt8.v z) == x /\ y == FStar.Pervasives.Native.Some (FStar.UInt8.v z, consumed)) <: Prims.logical) <: Prims.logical | _ -> let len = FStar.UInt8.v x - 128 in LowParse.Spec.Combinators.synth_injective (LowParse.Spec.DER.synth_be_int len) /\ (let res = LowParse.Spec.Base.parse (LowParse.Spec.Combinators.parse_synth (LowParse.Spec.SeqBytes.Base.parse_seq_flbytes len) (LowParse.Spec.DER.synth_be_int len)) input in (match res with | FStar.Pervasives.Native.None #_ -> y == FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ z consumed) -> len > 0 /\ (match z >= Prims.pow2 (8 * (len - 1)) with | true -> z <= LowParse.Spec.DER.der_length_max /\ LowParse.Spec.DER.tag_of_der_length z == x /\ y == FStar.Pervasives.Native.Some (z, consumed) | _ -> y == FStar.Pervasives.Native.None)) <: Prims.logical)) <: Prims.logical) <: Prims.logical)))
{ "end_col": 5, "end_line": 211, "start_col": 2, "start_line": 166 }
FStar.Pervasives.Lemma
val log256_eq (x: nat) : Lemma (requires (x > 0 /\ x < 4294967296)) (ensures (log256 x == log256' x))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let log256_eq x = log256_unique x (log256' x)
val log256_eq (x: nat) : Lemma (requires (x > 0 /\ x < 4294967296)) (ensures (log256 x == log256' x)) let log256_eq x =
false
null
true
log256_unique x (log256' x)
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "Prims.nat", "LowParse.Spec.DER.log256_unique", "LowParse.Spec.BoundedInt.log256'", "Prims.unit" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val log256_eq (x: nat) : Lemma (requires (x > 0 /\ x < 4294967296)) (ensures (log256 x == log256' x))
[]
LowParse.Spec.DER.log256_eq
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: Prims.nat -> FStar.Pervasives.Lemma (requires x > 0 /\ x < 4294967296) (ensures LowParse.Spec.DER.log256 x == LowParse.Spec.BoundedInt.log256' x)
{ "end_col": 29, "end_line": 920, "start_col": 2, "start_line": 920 }
FStar.Pervasives.Lemma
val serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y)))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; ()
val serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y))) let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y))) =
false
null
true
let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let x':der_length_t = U8.v x in if x' < 128 then () else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then (tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize (serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) (); serialize_u8_spec (U8.uint_to_t y); ()) else (let len:nat = U8.v x - 128 in synth_be_int_injective len; assert (serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) ()) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (FStar.Tactics.Effect.synth_by_tactic (fun _ -> (FStar.Tactics.trefl ()))) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) ()) (synth_der_length_greater_recip x len y)) (); serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); ()); ()
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.unit", "Prims.op_LessThan", "Prims.bool", "Prims.op_BarBar", "Prims.op_Equality", "FStar.UInt8.t", "FStar.UInt8.__uint_to_t", "LowParse.Spec.DER.tag_of_der_length_invalid", "LowParse.Spec.Int.serialize_u8_spec", "FStar.UInt8.uint_to_t", "LowParse.Spec.Combinators.serialize_synth_eq'", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Int.parse_u8_kind", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.op_GreaterThanOrEqual", "FStar.UInt8.v", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.Int.parse_u8", "LowParse.Spec.DER.synth_der_length_129", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.Int.serialize_u8", "LowParse.Spec.DER.synth_der_length_129_recip", "LowParse.Spec.Combinators.synth_inverse_intro'", "Prims.b2t", "LowParse.Spec.DER.tag_of_der_length_eq_129_eta", "LowParse.Spec.Base.serialize", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.serialize_synth", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.l_and", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.UInt.size", "FStar.UInt8.n", "LowParse.Spec.DER.tag_of_der_length_eq_129", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "Prims.op_Subtraction", "LowParse.Spec.DER.log256", "LowParse.Spec.Combinators.serialize_synth_eq", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.DER.lint", "LowParse.Spec.SeqBytes.Base.parse_seq_flbytes", "LowParse.Spec.DER.synth_be_int", "LowParse.Spec.SeqBytes.Base.serialize_seq_flbytes", "LowParse.Spec.DER.synth_be_int_recip", "LowParse.Spec.DER.synth_der_length_greater_recip", "Prims.pow2", "LowParse.Spec.DER.synth_der_length_greater", "LowParse.Spec.DER.serialize_der_length_payload_greater", "LowParse.Spec.DER.parse_der_length_payload_kind", "LowParse.Spec.DER.parse_der_length_payload", "LowParse.Spec.DER.serialize_der_length_payload", "LowParse.Spec.DER.synth_be_int_injective", "Prims.nat", "FStar.Pervasives.assert_norm", "Prims.l_True", "Prims.squash", "FStar.UInt8.lt", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "FStar.Endianness.n_to_be", "Prims.op_GreaterThan", "Prims.op_Multiply", "FStar.Seq.Base.seq", "LowParse.Spec.DER.parse_der_length_weak_kind", "LowParse.Spec.DER.parse_der_length_weak", "LowParse.Spec.DER.serialize_der_length_weak", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 6, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y)))
[]
LowParse.Spec.DER.serialize_der_length_weak_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
y: LowParse.Spec.DER.der_length_t -> FStar.Pervasives.Lemma (ensures (let res = LowParse.Spec.Base.serialize LowParse.Spec.DER.serialize_der_length_weak y in let x = LowParse.Spec.DER.tag_of_der_length y in let s1 = FStar.Seq.Base.create 1 x in (match FStar.UInt8.lt x 128uy with | true -> FStar.Seq.Base.equal res s1 | _ -> (match x = 129uy with | true -> y <= 255 /\ FStar.Seq.Base.equal res (FStar.Seq.Base.append s1 (FStar.Seq.Base.create 1 (FStar.UInt8.uint_to_t y))) | _ -> let len = LowParse.Spec.DER.log256 y in FStar.Seq.Base.equal res (FStar.Seq.Base.append s1 (FStar.Endianness.n_to_be len y)) ) <: Type0) <: Type0))
{ "end_col": 4, "end_line": 689, "start_col": 1, "start_line": 591 }
FStar.Pervasives.Lemma
val parse_der_length_payload32_unfold (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload32 x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (Cast.uint8_to_uint32 z, consumed) else let len : nat = U8.v x - 128 in 2 <= len /\ len <= 4 /\ ( let res : option (bounded_integer len & consumed_length input) = parse (parse_bounded_integer len) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if U32.v z >= pow2 (8 * (len - 1)) then U32.v z <= der_length_max /\ tag_of_der_length32 z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length32 x), consumed) else y == None ))))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end
val parse_der_length_payload32_unfold (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload32 x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (Cast.uint8_to_uint32 z, consumed) else let len : nat = U8.v x - 128 in 2 <= len /\ len <= 4 /\ ( let res : option (bounded_integer len & consumed_length input) = parse (parse_bounded_integer len) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if U32.v z >= pow2 (8 * (len - 1)) then U32.v z <= der_length_max /\ tag_of_der_length32 z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length32 x), consumed) else y == None )))) let parse_der_length_payload32_unfold x input =
false
null
true
parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in (match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then (Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y))); parse_der_length_payload_unfold x input; if U8.v x < 128 then () else if x = 128uy || x = 255uy then () else if x = 129uy then () else let len:nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_payload_size_of_tag", "LowParse.Bytes.bytes", "Prims.op_LessThan", "FStar.UInt8.v", "Prims.bool", "Prims.op_BarBar", "Prims.op_Equality", "FStar.UInt8.__uint_to_t", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Base.total_constant_size_parser_kind", "LowParse.Spec.DER.lint", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.Combinators.parse_synth", "FStar.Seq.Properties.lseq", "LowParse.Bytes.byte", "LowParse.Spec.SeqBytes.Base.parse_seq_flbytes", "LowParse.Spec.DER.synth_be_int", "LowParse.Spec.DER.be_int_of_bounded_integer", "Prims.unit", "LowParse.Spec.BoundedInt.integer_size_values", "LowParse.Spec.DER.parse_seq_flbytes_synth_be_int_eq", "LowParse.Spec.DER.be_int_of_bounded_integer_injective", "LowParse.Spec.DER.synth_be_int_injective", "Prims._assert", "Prims.l_and", "Prims.nat", "Prims.op_Subtraction", "LowParse.Spec.DER.parse_der_length_payload_unfold", "LowParse.Spec.Base.parse", "LowParse.Spec.Base.refine_with_tag", "LowParse.Spec.DER.der_length_t", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Spec.DER.parse_der_length_payload", "LowParse.Spec.Base.consumed_length", "Prims.op_GreaterThanOrEqual", "Prims.eq2", "Prims.int", "Prims.op_Addition", "LowParse.Spec.DER.log256", "LowParse.Math.pow2_lt_recip", "FStar.Mul.op_Star", "FStar.Pervasives.assert_norm", "Prims.pow2", "LowParse.Spec.DER.der_length_max", "LowParse.Spec.DER.parse_der_length_payload_kind", "FStar.UInt32.t", "LowParse.Spec.DER.tag_of_der_length32", "LowParse.Spec.DER.synth_der_length_payload32" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 4, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val parse_der_length_payload32_unfold (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload32 x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (Cast.uint8_to_uint32 z, consumed) else let len : nat = U8.v x - 128 in 2 <= len /\ len <= 4 /\ ( let res : option (bounded_integer len & consumed_length input) = parse (parse_bounded_integer len) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if U32.v z >= pow2 (8 * (len - 1)) then U32.v z <= der_length_max /\ tag_of_der_length32 z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length32 x), consumed) else y == None ))))
[]
LowParse.Spec.DER.parse_der_length_payload32_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: FStar.UInt8.t{LowParse.Spec.DER.der_length_payload_size_of_tag x <= 4} -> input: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures (let y = LowParse.Spec.Base.parse (LowParse.Spec.DER.parse_der_length_payload32 x) input in 256 < LowParse.Spec.DER.der_length_max /\ (match FStar.UInt8.v x < 128 with | true -> LowParse.Spec.DER.tag_of_der_length (FStar.UInt8.v x) == x /\ y == FStar.Pervasives.Native.Some (FStar.Int.Cast.uint8_to_uint32 x, 0) | _ -> (match x = 128uy || x = 255uy with | true -> y == FStar.Pervasives.Native.None | _ -> (match x = 129uy with | true -> (match LowParse.Spec.Base.parse LowParse.Spec.Int.parse_u8 input with | FStar.Pervasives.Native.None #_ -> y == FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ z consumed) -> (match FStar.UInt8.v z < 128 with | true -> y == FStar.Pervasives.Native.None | _ -> LowParse.Spec.DER.tag_of_der_length (FStar.UInt8.v z) == x /\ y == FStar.Pervasives.Native.Some (FStar.Int.Cast.uint8_to_uint32 z, consumed)) <: Prims.logical) <: Prims.logical | _ -> let len = FStar.UInt8.v x - 128 in 2 <= len /\ len <= 4 /\ (let res = LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer len ) input in (match res with | FStar.Pervasives.Native.None #_ -> y == FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ z consumed) -> len > 0 /\ (match FStar.UInt32.v z >= Prims.pow2 (8 * (len - 1)) with | true -> FStar.UInt32.v z <= LowParse.Spec.DER.der_length_max /\ LowParse.Spec.DER.tag_of_der_length32 z == x /\ y == FStar.Pervasives.Native.Some (z, consumed) | _ -> y == FStar.Pervasives.Native.None)) <: Prims.logical)) <: Prims.logical) <: Prims.logical)))
{ "end_col": 7, "end_line": 914, "start_col": 2, "start_line": 879 }
FStar.Pervasives.Lemma
val serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y)))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y
val serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y))) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y))) =
false
null
true
serialize_synth_eq _ (fun (y: der_length_t{min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max)) (fun (y: bounded_int min max) -> (y <: (y: der_length_t{min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.bounded_int", "LowParse.Spec.DER.serialize_der_length_weak_unfold", "Prims.unit", "LowParse.Spec.Combinators.serialize_synth_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.DER.parse_der_length_weak_kind", "Prims.op_AmpAmp", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.DER.parse_der_length_weak", "Prims.bool", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.DER.serialize_der_length_weak", "Prims.l_True", "Prims.squash", "FStar.UInt8.lt", "FStar.UInt8.__uint_to_t", "FStar.Seq.Base.equal", "LowParse.Bytes.byte", "Prims.op_Equality", "FStar.UInt8.t", "Prims.l_and", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "FStar.UInt8.uint_to_t", "FStar.Endianness.n_to_be", "Prims.nat", "Prims.op_GreaterThan", "Prims.pow2", "Prims.op_Multiply", "Prims.op_Subtraction", "Prims.op_LessThan", "LowParse.Spec.DER.log256", "FStar.Seq.Base.seq", "LowParse.Spec.DER.tag_of_der_length", "LowParse.Bytes.bytes", "LowParse.Spec.Base.serialize", "LowParse.Spec.DER.parse_bounded_der_length_kind", "LowParse.Spec.DER.parse_bounded_der_length", "LowParse.Spec.DER.serialize_bounded_der_length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y)
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t{min <= max}) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` (Seq.create 1 (U8.uint_to_t y))) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` (E.n_to_be len y)))
[]
LowParse.Spec.DER.serialize_bounded_der_length_unfold
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max} -> y: LowParse.Spec.DER.bounded_int min max -> FStar.Pervasives.Lemma (ensures (let res = LowParse.Spec.Base.serialize (LowParse.Spec.DER.serialize_bounded_der_length min max) y in let x = LowParse.Spec.DER.tag_of_der_length y in let s1 = FStar.Seq.Base.create 1 x in (match FStar.UInt8.lt x 128uy with | true -> FStar.Seq.Base.equal res s1 | _ -> (match x = 129uy with | true -> y <= 255 /\ FStar.Seq.Base.equal res (FStar.Seq.Base.append s1 (FStar.Seq.Base.create 1 (FStar.UInt8.uint_to_t y))) | _ -> let len = LowParse.Spec.DER.log256 y in FStar.Seq.Base.equal res (FStar.Seq.Base.append s1 (FStar.Endianness.n_to_be len y)) ) <: Type0) <: Type0))
{ "end_col": 36, "end_line": 743, "start_col": 2, "start_line": 733 }
FStar.Pervasives.Lemma
val serialize_bounded_der_length32_size (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (y': bounded_int32 min max) : Lemma ( Seq.length (serialize (serialize_bounded_der_length32 min max) y') == ( if y' `U32.lt` 128ul then 1 else if y' `U32.lt` 256ul then 2 else if y' `U32.lt` 65536ul then 3 else if y' `U32.lt` 16777216ul then 4 else 5 ))
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "E" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.SeqBytes.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "LowParse.Math", "short_module": "Math" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.UInt", "short_module": "UInt" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let serialize_bounded_der_length32_size min max y' = serialize_bounded_der_length32_unfold min max y'
val serialize_bounded_der_length32_size (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (y': bounded_int32 min max) : Lemma ( Seq.length (serialize (serialize_bounded_der_length32 min max) y') == ( if y' `U32.lt` 128ul then 1 else if y' `U32.lt` 256ul then 2 else if y' `U32.lt` 65536ul then 3 else if y' `U32.lt` 16777216ul then 4 else 5 )) let serialize_bounded_der_length32_size min max y' =
false
null
true
serialize_bounded_der_length32_unfold min max y'
{ "checked_file": "LowParse.Spec.DER.fst.checked", "dependencies": [ "prims.fst.checked", "LowParse.Spec.SeqBytes.Base.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Math.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Endianness.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.DER.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Spec.DER.serialize_bounded_der_length32_unfold", "Prims.unit" ]
[]
module LowParse.Spec.DER open LowParse.Spec.Combinators open LowParse.Spec.SeqBytes.Base // include LowParse.Spec.VLData // for in_bounds open FStar.Mul module U8 = FStar.UInt8 module UInt = FStar.UInt module Math = LowParse.Math module E = FStar.Endianness module Seq = FStar.Seq #reset-options "--z3cliopt smt.arith.nl=false --max_fuel 0 --max_ifuel 0" // let _ : unit = _ by (FStar.Tactics.(print (string_of_int der_length_max); exact (`()))) let der_length_max_eq = assert_norm (der_length_max == pow2 (8 * 126) - 1) let rec log256 (x: nat { x > 0 }) : Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) = assert_norm (pow2 8 == 256); if x < 256 then 1 else begin let n = log256 (x / 256) in Math.pow2_plus (8 * (n - 1)) 8; Math.pow2_plus (8 * n) 8; n + 1 end let log256_unique x y = Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x); Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) let log256_le x1 x2 = Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) let der_length_payload_size_le x1 x2 = if x1 < 128 || x2 < 128 then () else let len_len2 = log256 x2 in let len_len1 = log256 x1 in log256_le x1 x2; assert_norm (pow2 7 == 128); assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len2 - 1)) (8 * 126) let synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) = E.lemma_be_to_n_is_bounded b; E.be_to_n b let synth_be_int_injective (len: nat) : Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] = synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) -> E.be_to_n_inj x x' ) let synth_der_length_129 (x: U8.t { x == 129uy } ) (y: U8.t { U8.v y >= 128 } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); log256_unique (U8.v y) 1; U8.v y let synth_der_length_greater (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x - 128 } ) (y: lint len { y >= pow2 (8 * (len - 1)) } ) : Tot (refine_with_tag tag_of_der_length x) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len; y let parse_der_length_payload (x: U8.t) : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin weaken (parse_der_length_payload_kind x) (parse_ret (x' <: refine_with_tag tag_of_der_length x)) end else if x = 128uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // DER representation of 0 is covered by the x<128 case else if x = 255uy then fail_parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) // forbidden in BER already else if x = 129uy then weaken (parse_der_length_payload_kind x) ((parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) `parse_synth` synth_der_length_129 x) else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? weaken (parse_der_length_payload_kind x) (((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) `parse_synth` synth_der_length_greater x len) end let parse_der_length_payload_unfold (x: U8.t) (input: bytes) : Lemma ( let y = parse (parse_der_length_payload x) input in (256 < der_length_max) /\ ( if U8.v x < 128 then tag_of_der_length (U8.v x) == x /\ y == Some (U8.v x, 0) else if x = 128uy || x = 255uy then y == None else if x = 129uy then match parse parse_u8 input with | None -> y == None | Some (z, consumed) -> if U8.v z < 128 then y == None else tag_of_der_length (U8.v z) == x /\ y == Some (U8.v z, consumed) else let len : nat = U8.v x - 128 in synth_injective (synth_be_int len) /\ ( let res : option (lint len & consumed_length input) = parse (parse_synth (parse_seq_flbytes len) (synth_be_int len)) input in match res with | None -> y == None | Some (z, consumed) -> len > 0 /\ ( if z >= pow2 (8 * (len - 1)) then z <= der_length_max /\ tag_of_der_length z == x /\ y == Some ((z <: refine_with_tag tag_of_der_length x), consumed) else y == None )))) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy then () else if x = 255uy then () else if x = 129uy then begin parse_synth_eq (parse_u8 `parse_filter` (fun y -> U8.v y >= 128)) (synth_der_length_129 x) input; parse_filter_eq parse_u8 (fun y -> U8.v y >= 128) input; match parse parse_u8 input with | None -> () | Some (y, _) -> if U8.v y >= 128 then begin log256_unique (U8.v y) 1 end else () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? parse_synth_eq ((parse_seq_flbytes len `parse_synth` (synth_be_int len)) `parse_filter` (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) (synth_der_length_greater x len) input; parse_filter_eq (parse_seq_flbytes len `parse_synth` (synth_be_int len)) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) input; assert (len > 1); let res : option (lint len & consumed_length input) = parse (parse_seq_flbytes len `parse_synth` (synth_be_int len)) input in match res with | None -> () | Some (y, _) -> if y >= pow2 (8 * (len - 1)) then begin let (y: lint len { y >= pow2 (8 * (len - 1)) } ) = y in Math.pow2_le_compat (8 * 126) (8 * len); Math.pow2_le_compat (8 * (len - 1)) 7; log256_unique y len end else () end inline_for_extraction let parse_der_length_payload_kind_weak : parser_kind = strong_parser_kind 0 126 None inline_for_extraction let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak let parse_der_length_weak : parser parse_der_length_weak_kind der_length_t = parse_tagged_union parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) [@@(noextract_to "krml")] let parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = [@inline_let] let _ = der_length_payload_size_le min max in strong_parser_kind (der_length_payload_size min) (der_length_payload_size max) None let bounded_int (min: der_length_t) (max: der_length_t { min <= max }) : Tot Type = (x: int { min <= x /\ x <= max }) let parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t) : Tot bool = let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max inline_for_extraction // for parser_kind let tag_of_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) (x: bounded_int min max) : Tot (y: U8.t { parse_bounded_der_length_tag_cond min max y == true } ) = [@inline_let] let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in tag_of_der_length x let parse_bounded_der_length_payload (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) : Tot (parser (parse_bounded_der_length_payload_kind min max) (refine_with_tag (tag_of_bounded_der_length min max) x)) = weaken (parse_bounded_der_length_payload_kind min max) (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) `parse_synth` (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x))) [@@(noextract_to "krml")] let parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t { min <= max } ) : Tot parser_kind = and_then_kind (parse_filter_kind parse_u8_kind) (parse_bounded_der_length_payload_kind min max) let parse_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_bounded_der_length_kind min max) (bounded_int min max)) = parse_tagged_union (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) (* equality *) let parse_bounded_der_length_payload_unfold (min: der_length_t) (max: der_length_t { min <= max }) (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) (input' : bytes) : Lemma (parse (parse_bounded_der_length_payload min max x) input' == ( match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_y) else None )) = parse_synth_eq (parse_der_length_payload x `parse_filter` (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max)) (fun (y: refine_with_tag tag_of_der_length x { min <= y && y <= max }) -> (y <: refine_with_tag (tag_of_bounded_der_length min max) x)) input' ; parse_filter_eq (parse_der_length_payload x) (fun (y: refine_with_tag tag_of_der_length x) -> min <= y && y <= max) input' let parse_bounded_der_length_unfold_aux (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_bounded_der_length_payload min max x) input' with | Some (y, consumed_y) -> Some (y, consumed_x + consumed_y) | None -> None else None )) = parse_tagged_union_eq (parse_u8 `parse_filter` parse_bounded_der_length_tag_cond min max) (tag_of_bounded_der_length min max) (parse_bounded_der_length_payload min max) input; parse_filter_eq parse_u8 (parse_bounded_der_length_tag_cond min max) input let parse_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length min max) input == (match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None else None )) = parse_bounded_der_length_unfold_aux min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in parse_bounded_der_length_payload_unfold min max (x <: (x: U8.t { parse_bounded_der_length_tag_cond min max x == true } ) ) input' else () let parse_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (parser (parse_filter_kind parse_der_length_weak_kind) (bounded_int min max)) = parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max) `parse_synth` (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) let parse_bounded_der_length_weak_unfold (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (parse (parse_bounded_der_length_weak min max) input == ( match parse parse_u8 input with | None -> None | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> None | Some (y, consumed_y) -> if min <= y && y <= max then Some (y, consumed_x + consumed_y) else None end )) = parse_synth_eq (parse_der_length_weak `parse_filter` (fun y -> min <= y && y <= max)) (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) input; parse_filter_eq parse_der_length_weak (fun y -> min <= y && y <= max) input; parse_tagged_union_eq parse_u8 tag_of_der_length (fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) input let parse_bounded_der_length_eq (min: der_length_t) (max: der_length_t { min <= max }) (input: bytes) : Lemma (ensures (parse (parse_bounded_der_length min max) input == parse (parse_bounded_der_length_weak min max) input)) = parse_bounded_der_length_unfold min max input; parse_bounded_der_length_weak_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let input' = Seq.slice input consumed_x (Seq.length input) in begin match parse (parse_der_length_payload x) input' with | None -> () | Some (y, consumed_y) -> if min <= y && y <= max then (der_length_payload_size_le min y; der_length_payload_size_le y max) else () end (* serializer *) let tag_of_der_length_lt_128 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) < 128)) (ensures (x == U8.v (tag_of_der_length x))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_invalid (x: der_length_t) : Lemma (requires (let y = U8.v (tag_of_der_length x) in y == 128 \/ y == 255)) (ensures False) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let tag_of_der_length_eq_129 (x: der_length_t) : Lemma (requires (U8.v (tag_of_der_length x) == 129)) (ensures (x >= 128 /\ x < 256)) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126) let synth_der_length_129_recip (x: U8.t { x == 129uy }) (y: refine_with_tag tag_of_der_length x) : GTot (y: U8.t {U8.v y >= 128}) = tag_of_der_length_eq_129 y; U8.uint_to_t y let synth_be_int_recip (len: nat) (x: lint len) : GTot (b: Seq.lseq byte len) = E.n_to_be len x let synth_be_int_inverse (len: nat) : Lemma (synth_inverse (synth_be_int len) (synth_be_int_recip len)) = () let synth_der_length_greater_recip (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) (y: refine_with_tag tag_of_der_length x) : Tot (y: lint len { y >= pow2 (8 * (len - 1)) } ) = assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); y let synth_der_length_greater_inverse (x: U8.t { U8.v x > 129 /\ U8.v x < 255 } ) (len: nat { len == U8.v x % 128 } ) : Lemma (synth_inverse (synth_der_length_greater x len) (synth_der_length_greater_recip x len)) = () private let serialize_der_length_payload_greater (x: U8.t { not (U8.v x < 128 || x = 128uy || x = 255uy || x = 129uy) } ) (len: nat { len == U8.v x - 128 } ) = (serialize_synth #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () ) let tag_of_der_length_lt_128_eta (x:U8.t{U8.v x < 128}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_lt_128 y <: Lemma (U8.v x == y) let tag_of_der_length_invalid_eta (x:U8.t{U8.v x == 128 \/ U8.v x == 255}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_invalid y <: Lemma False let tag_of_der_length_eq_129_eta (x:U8.t{U8.v x == 129}) = fun (y: refine_with_tag tag_of_der_length x) -> tag_of_der_length_eq_129 y <: Lemma (synth_der_length_129 x (synth_der_length_129_recip x y) == y) let serialize_der_length_payload (x: U8.t) : Tot (serializer (parse_der_length_payload x)) = assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_ret (x' <: refine_with_tag tag_of_der_length x) (tag_of_der_length_lt_128_eta x)) end else if x = 128uy || x = 255uy then fail_serializer (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x) (tag_of_der_length_invalid_eta x) else if x = 129uy then begin serialize_weaken (parse_der_length_payload_kind x) (serialize_synth (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) ) end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? serialize_weaken (parse_der_length_payload_kind x) (serialize_der_length_payload_greater x len) end let serialize_der_length_weak : serializer parse_der_length_weak = serialize_tagged_union serialize_u8 tag_of_der_length (fun x -> serialize_weaken parse_der_length_payload_kind_weak (serialize_der_length_payload x)) #push-options "--max_ifuel 6 --z3rlimit 64" let serialize_der_length_weak_unfold (y: der_length_t) : Lemma (let res = serialize serialize_der_length_weak y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = let x = tag_of_der_length y in serialize_u8_spec x; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 7 == 128); assert_norm (pow2 8 == 256); assert_norm (256 < der_length_max); assert (U8.v x <= der_length_max); let (x' : der_length_t) = U8.v x in if x' < 128 then begin () end else if x = 128uy || x = 255uy then tag_of_der_length_invalid y else if x = 129uy then begin tag_of_der_length_eq_129 y; assert (U8.v (synth_der_length_129_recip x y) == y); let s1 = serialize ( serialize_synth #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x))) y in serialize_synth_eq' #_ #(parse_filter_refine #U8.t (fun y -> U8.v y >= 128)) #(refine_with_tag tag_of_der_length x) (parse_filter parse_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129 x) (serialize_filter serialize_u8 (fun y -> U8.v y >= 128)) (synth_der_length_129_recip x) (synth_inverse_intro' (synth_der_length_129 x) (synth_der_length_129_recip x) (tag_of_der_length_eq_129_eta x)) y s1 () (serialize serialize_u8 (synth_der_length_129_recip x y)) () ; serialize_u8_spec (U8.uint_to_t y); () end else begin let len : nat = U8.v x - 128 in synth_be_int_injective len; // FIXME: WHY WHY WHY does the pattern not trigger, even with higher rlimit? assert ( serialize (serialize_der_length_payload x) y == serialize (serialize_der_length_payload_greater x len) y ); serialize_synth_eq' #_ #(parse_filter_refine #(lint len) (fun (y: lint len) -> y >= pow2 (8 * (len - 1)))) #(refine_with_tag tag_of_der_length x) _ (synth_der_length_greater x len) (serialize_filter (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (fun (y: lint len) -> y >= pow2 (8 * (len - 1))) ) (synth_der_length_greater_recip x len) () y (serialize (serialize_der_length_payload_greater x len) y) (_ by (FStar.Tactics.trefl ())) (serialize (serialize_synth #_ #(Seq.lseq byte len) #(lint len) _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () ) (synth_der_length_greater_recip x len y) ) () ; serialize_synth_eq _ (synth_be_int len) (serialize_seq_flbytes len) (synth_be_int_recip len) () (synth_der_length_greater_recip x len y); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); () end; () #pop-options let serialize_bounded_der_length_weak (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length_weak min max)) = serialize_synth _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () let serialize_bounded_der_length (min: der_length_t) (max: der_length_t { min <= max }) : Tot (serializer (parse_bounded_der_length min max)) = Classical.forall_intro (parse_bounded_der_length_eq min max); serialize_ext _ (serialize_bounded_der_length_weak min max) (parse_bounded_der_length min max) let serialize_bounded_der_length_unfold (min: der_length_t) (max: der_length_t { min <= max }) (y: bounded_int min max) : Lemma (let res = serialize (serialize_bounded_der_length min max) y in let x = tag_of_der_length y in let s1 = Seq.create 1 x in if x `U8.lt` 128uy then res `Seq.equal` s1 else if x = 129uy then y <= 255 /\ res `Seq.equal` (s1 `Seq.append` Seq.create 1 (U8.uint_to_t y)) else let len = log256 y in res `Seq.equal` (s1 `Seq.append` E.n_to_be len y) ) = serialize_synth_eq _ (fun (y: der_length_t {min <= y && y <= max}) -> (y <: bounded_int min max)) (serialize_filter serialize_der_length_weak (fun y -> min <= y && y <= max) ) (fun (y : bounded_int min max) -> (y <: (y: der_length_t {min <= y && y <= max}))) () y; serialize_der_length_weak_unfold y (* 32-bit spec *) module U32 = FStar.UInt32 let der_length_payload_size_of_tag_inv32 (x: der_length_t) : Lemma (requires (x < 4294967296)) (ensures ( tag_of_der_length x == ( if x < 128 then U8.uint_to_t x else if x < 256 then 129uy else if x < 65536 then 130uy else if x < 16777216 then 131uy else 132uy ))) = if x < 128 then () else let len_len = log256 x in assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (len_len - 1)) (8 * 126); assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); if x < 256 then log256_unique x 1 else if x < 65536 then log256_unique x 2 else if x < 16777216 then log256_unique x 3 else log256_unique x 4 let synth_der_length_payload32 (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) (y: refine_with_tag tag_of_der_length x) : GTot (refine_with_tag tag_of_der_length32 x) = let _ = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end in U32.uint_to_t y let synth_der_length_payload32_injective (x: U8.t { der_length_payload_size_of_tag x <= 4 } ) : Lemma (synth_injective (synth_der_length_payload32 x)) [SMTPat (synth_injective (synth_der_length_payload32 x))] = assert_norm (der_length_max == pow2 (8 * 126) - 1); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in synth_injective_intro' (synth_der_length_payload32 x) (fun (y1 y2: refine_with_tag tag_of_der_length x) -> if y1 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y1 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y1) == 128 + log256 y1) end; if y2 >= 128 then begin Math.pow2_lt_recip (8 * (log256 y2 - 1)) (8 * 126); assert (U8.v (tag_of_der_length y2) == 128 + log256 y2) end ) let parse_der_length_payload32 x : Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length32 x)) = parse_der_length_payload x `parse_synth` synth_der_length_payload32 x let be_int_of_bounded_integer (len: integer_size) (x: nat { x < pow2 (8 * len) } ) : GTot (bounded_integer len) = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); U32.uint_to_t x let be_int_of_bounded_integer_injective (len: integer_size) : Lemma (synth_injective (be_int_of_bounded_integer len)) [SMTPat (synth_injective (be_int_of_bounded_integer len))] // FIXME: WHY WHY WHY does this pattern NEVER trigger? = integer_size_values len; assert_norm (pow2 (8 * 1) == 256); assert_norm (pow2 (8 * 2) == 65536); assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296) #push-options "--max_ifuel 4 --z3rlimit 16" let parse_seq_flbytes_synth_be_int_eq (len: integer_size) (input: bytes) : Lemma ( let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse ( parse_synth #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len) ) (be_int_of_bounded_integer len) ) input == parse (parse_bounded_integer len) input) = let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_synth_eq (parse_seq_flbytes len `parse_synth` synth_be_int len) (be_int_of_bounded_integer len) input; parse_synth_eq (parse_seq_flbytes len) (synth_be_int len) input; parser_kind_prop_equiv (parse_bounded_integer_kind len) (parse_bounded_integer len); parse_bounded_integer_spec len input let parse_der_length_payload32_unfold x input = parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input; assert_norm (der_length_max == pow2 (8 * 126) - 1); assert_norm (pow2 (8 * 1) == 256); let _ = assert_norm (pow2 (8 * 2) == 65536) in let _ = assert_norm (pow2 (8 * 3) == 16777216) in let _ = assert_norm (pow2 (8 * 4) == 4294967296) in begin match parse (parse_der_length_payload x) input with | None -> () | Some (y, _) -> if y >= 128 then begin Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end end; parse_der_length_payload_unfold x input; if U8.v x < 128 then () // tag_of_der_length (U8.v x) == x /\ y == Some (Cast.uint8_to_uint32 x, 0) else if x = 128uy || x = 255uy then () // y == None else if x = 129uy then () else begin let len : nat = U8.v x - 128 in assert (2 <= len /\ len <= 4); let _ = synth_be_int_injective len in let _ = be_int_of_bounded_integer_injective len in parse_seq_flbytes_synth_be_int_eq len input; integer_size_values len; parse_synth_eq #_ #(lint len) #(bounded_integer len) (parse_synth #_ #(Seq.lseq byte len) #(lint len) (parse_seq_flbytes len) (synth_be_int len)) (be_int_of_bounded_integer len) input end #pop-options let log256_eq x = log256_unique x (log256' x) let synth_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int min max) : Tot (bounded_int32 min max) = U32.uint_to_t x let parse_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (parser (parse_bounded_der_length32_kind min max) (bounded_int32 min max)) = parse_bounded_der_length min max `parse_synth` synth_bounded_der_length32 min max #push-options "--z3rlimit 50" let parse_bounded_der_length32_unfold min max input = parse_synth_eq (parse_bounded_der_length min max) (synth_bounded_der_length32 min max) input; parse_bounded_der_length_unfold min max input; match parse parse_u8 input with | None -> () | Some (x, consumed_x) -> let len = der_length_payload_size_of_tag x in if der_length_payload_size min <= len && len <= der_length_payload_size max then let input' = Seq.slice input consumed_x (Seq.length input) in assert_norm (4294967296 <= der_length_max); der_length_payload_size_le max 4294967295; assert_norm (pow2 (8 * 3) == 16777216); assert_norm (pow2 (8 * 4) == 4294967296); log256_unique 4294967295 4; parse_synth_eq (parse_der_length_payload x) (synth_der_length_payload32 x) input' ; match parse (parse_der_length_payload x) input' with | None -> () | Some (y, _) -> if y >= 128 then begin assert_norm (der_length_max == pow2 (8 * 126) - 1); Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126); assert (U8.v (tag_of_der_length y) == 128 + log256 y) end else () #pop-options let synth_bounded_der_length32_recip (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (x: bounded_int32 min max) : GTot (bounded_int min max) = U32.v x let serialize_bounded_der_length32 (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) : Tot (serializer (parse_bounded_der_length32 min max)) = serialize_synth _ (synth_bounded_der_length32 min max) (serialize_bounded_der_length min max) (synth_bounded_der_length32_recip min max) () let serialize_bounded_der_length32_unfold min max y' = serialize_synth_eq _ (synth_bounded_der_length32 min max) (serialize_bounded_der_length min max) (synth_bounded_der_length32_recip min max) () y'; serialize_bounded_der_length_unfold min max (U32.v y'); let x = tag_of_der_length32_impl y' in if x `U8.lt` 128uy then () else if x = 129uy then FStar.Math.Lemmas.small_modulo_lemma_1 (U32.v y') 256 else begin assert (x <> 128uy /\ x <> 255uy); let len = log256' (U32.v y') in log256_eq (U32.v y'); serialize_bounded_integer_spec len y' end #push-options "--z3rlimit 20" let serialize_bounded_der_length32_size
false
false
LowParse.Spec.DER.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val serialize_bounded_der_length32_size (min: der_length_t) (max: der_length_t { min <= max /\ max < 4294967296 }) (y': bounded_int32 min max) : Lemma ( Seq.length (serialize (serialize_bounded_der_length32 min max) y') == ( if y' `U32.lt` 128ul then 1 else if y' `U32.lt` 256ul then 2 else if y' `U32.lt` 65536ul then 3 else if y' `U32.lt` 16777216ul then 4 else 5 ))
[]
LowParse.Spec.DER.serialize_bounded_der_length32_size
{ "file_name": "src/lowparse/LowParse.Spec.DER.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max /\ max < 4294967296} -> y': LowParse.Spec.BoundedInt.bounded_int32 min max -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.length (LowParse.Spec.Base.serialize (LowParse.Spec.DER.serialize_bounded_der_length32 min max) y') == (match FStar.UInt32.lt y' 128ul with | true -> 1 | _ -> (match FStar.UInt32.lt y' 256ul with | true -> 2 | _ -> (match FStar.UInt32.lt y' 65536ul with | true -> 3 | _ -> (match FStar.UInt32.lt y' 16777216ul with | true -> 4 | _ -> 5) <: Prims.int) <: Prims.int) <: Prims.int))
{ "end_col": 50, "end_line": 1008, "start_col": 2, "start_line": 1008 }
Prims.Tot
[ { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let nt (x:var) (t:term) = [ NT x t ]
let nt (x: var) (t: term) =
false
null
false
[NT x t]
{ "checked_file": "Pulse.Typing.Metatheory.Base.fsti.checked", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "prims.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.Metatheory.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.var", "Pulse.Syntax.Base.term", "Prims.Cons", "Pulse.Syntax.Naming.subst_elt", "Pulse.Syntax.Naming.NT", "Prims.Nil", "Prims.list" ]
[]
module Pulse.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing let comp_typing_u (g:env) (c:comp_st) = comp_typing g c (comp_u c) val admit_comp_typing (g:env) (c:comp_st) : comp_typing_u g c val st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st) (_:st_typing g t c) : comp_typing_u g c val comp_typing_inversion (#g:env) (#c:comp_st) (ct:comp_typing_u g c) : st_comp_typing g (st_comp_of_comp c) val st_comp_typing_inversion_cofinite (#g:env) (#st:_) (ct:st_comp_typing g st) : (universe_of g st.res st.u & tot_typing g st.pre tm_vprop & (x:var{fresh_wrt x g (freevars st.post)} -> //this part is tricky, to get the quantification on x tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop)) val st_comp_typing_inversion (#g:env) (#st:_) (ct:st_comp_typing g st) : (universe_of g st.res st.u & tot_typing g st.pre tm_vprop & x:var{fresh_wrt x g (freevars st.post)} & tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop) val tm_exists_inversion (#g:env) (#u:universe) (#ty:term) (#p:term) (_:tot_typing g (tm_exists_sl u (as_binder ty) p) tm_vprop) (x:var { fresh_wrt x g (freevars p) } ) : universe_of g ty u & tot_typing (push_binding g x ppname_default ty) p tm_vprop val pure_typing_inversion (#g:env) (#p:term) (_:tot_typing g (tm_pure p) tm_vprop) : tot_typing g p (tm_fstar FStar.Reflection.Typing.tm_prop Range.range_0) val tot_typing_weakening (g:env) (g':env { disjoint g g' }) (t:term) (ty:typ) (_:tot_typing (push_env g g') t ty) (g1:env { pairwise_disjoint g g1 g' }) : tot_typing (push_env (push_env g g1) g') t ty val st_typing_weakening (g:env) (g':env { disjoint g g' }) (t:st_term) (c:comp) (_:st_typing (push_env g g') t c) (g1:env { pairwise_disjoint g g1 g' }) : st_typing (push_env (push_env g g1) g') t c let veq_weakening (g:env) (g':env { disjoint g g' }) (#v1 #v2:vprop) (_:vprop_equiv (push_env g g') v1 v2) (g1:env { pairwise_disjoint g g1 g' }) : vprop_equiv (push_env (push_env g g1) g') v1 v2 = magic ()
false
true
Pulse.Typing.Metatheory.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val nt : x: Pulse.Syntax.Base.var -> t: Pulse.Syntax.Base.term -> Prims.list Pulse.Syntax.Naming.subst_elt
[]
Pulse.Typing.Metatheory.Base.nt
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
x: Pulse.Syntax.Base.var -> t: Pulse.Syntax.Base.term -> Prims.list Pulse.Syntax.Naming.subst_elt
{ "end_col": 36, "end_line": 57, "start_col": 26, "start_line": 57 }
Prims.Tot
[ { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax.Naming", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing.Metatheory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let comp_typing_u (g:env) (c:comp_st) = comp_typing g c (comp_u c)
let comp_typing_u (g: env) (c: comp_st) =
false
null
false
comp_typing g c (comp_u c)
{ "checked_file": "Pulse.Typing.Metatheory.Base.fsti.checked", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.Naming.fsti.checked", "Pulse.Syntax.fst.checked", "prims.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.Metatheory.Base.fsti" }
[ "total" ]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.comp_typing", "Pulse.Syntax.Base.comp_u" ]
[]
module Pulse.Typing.Metatheory.Base open Pulse.Syntax open Pulse.Syntax.Naming open Pulse.Typing
false
false
Pulse.Typing.Metatheory.Base.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val comp_typing_u : g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0
[]
Pulse.Typing.Metatheory.Base.comp_typing_u
{ "file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0
{ "end_col": 66, "end_line": 6, "start_col": 40, "start_line": 6 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let md5_hash_len = 16ul
let md5_hash_len =
false
null
false
16ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val md5_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.md5_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 35, "end_line": 5, "start_col": 31, "start_line": 5 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let blake2s_hash_len = 32ul
let blake2s_hash_len =
false
null
false
32ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul [@ CMacro ] let sha2_256_hash_len = 32ul [@ CMacro ] let sha2_384_hash_len = 48ul [@ CMacro ] let sha2_512_hash_len = 64ul [@ CMacro ] let sha3_224_hash_len = 28ul [@ CMacro ] let sha3_256_hash_len = 32ul [@ CMacro ] let sha3_384_hash_len = 48ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2s_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.blake2s_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 39, "end_line": 15, "start_col": 35, "start_line": 15 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha3_384_hash_len = 48ul
let sha3_384_hash_len =
false
null
false
48ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul [@ CMacro ] let sha2_256_hash_len = 32ul [@ CMacro ] let sha2_384_hash_len = 48ul [@ CMacro ] let sha2_512_hash_len = 64ul [@ CMacro ] let sha3_224_hash_len = 28ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha3_384_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha3_384_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 13, "start_col": 36, "start_line": 13 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha1_hash_len = 20ul
let sha1_hash_len =
false
null
false
20ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *)
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha1_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha1_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 36, "end_line": 6, "start_col": 32, "start_line": 6 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha2_224_hash_len = 28ul
let sha2_224_hash_len =
false
null
false
28ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha2_224_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha2_224_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 7, "start_col": 36, "start_line": 7 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha2_384_hash_len = 48ul
let sha2_384_hash_len =
false
null
false
48ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha2_384_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha2_384_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 9, "start_col": 36, "start_line": 9 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha2_512_hash_len = 64ul
let sha2_512_hash_len =
false
null
false
64ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul [@ CMacro ] let sha2_256_hash_len = 32ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha2_512_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha2_512_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 10, "start_col": 36, "start_line": 10 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha2_256_hash_len = 32ul
let sha2_256_hash_len =
false
null
false
32ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha2_256_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha2_256_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 8, "start_col": 36, "start_line": 8 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha3_512_hash_len = 64ul
let sha3_512_hash_len =
false
null
false
64ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul [@ CMacro ] let sha2_256_hash_len = 32ul [@ CMacro ] let sha2_384_hash_len = 48ul [@ CMacro ] let sha2_512_hash_len = 64ul [@ CMacro ] let sha3_224_hash_len = 28ul [@ CMacro ] let sha3_256_hash_len = 32ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha3_512_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha3_512_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 14, "start_col": 36, "start_line": 14 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha3_256_hash_len = 32ul
let sha3_256_hash_len =
false
null
false
32ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul [@ CMacro ] let sha2_256_hash_len = 32ul [@ CMacro ] let sha2_384_hash_len = 48ul [@ CMacro ] let sha2_512_hash_len = 64ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha3_256_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha3_256_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 12, "start_col": 36, "start_line": 12 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let sha3_224_hash_len = 28ul
let sha3_224_hash_len =
false
null
false
28ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul [@ CMacro ] let sha2_256_hash_len = 32ul [@ CMacro ] let sha2_384_hash_len = 48ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val sha3_224_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.sha3_224_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 40, "end_line": 11, "start_col": 36, "start_line": 11 }
Prims.Tot
[ { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Hash.Incremental", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let blake2b_hash_len = 64ul
let blake2b_hash_len =
false
null
false
64ul
{ "checked_file": "EverCrypt.Hash.Incremental.Macros.fst.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.Incremental.Macros.fst" }
[ "total" ]
[ "FStar.UInt32.__uint_to_t" ]
[]
// Separate module because -no-prefix module EverCrypt.Hash.Incremental.Macros (* These definitions for the benefits of C clients. *) [@ CMacro ] let md5_hash_len = 16ul [@ CMacro ] let sha1_hash_len = 20ul [@ CMacro ] let sha2_224_hash_len = 28ul [@ CMacro ] let sha2_256_hash_len = 32ul [@ CMacro ] let sha2_384_hash_len = 48ul [@ CMacro ] let sha2_512_hash_len = 64ul [@ CMacro ] let sha3_224_hash_len = 28ul [@ CMacro ] let sha3_256_hash_len = 32ul [@ CMacro ] let sha3_384_hash_len = 48ul [@ CMacro ] let sha3_512_hash_len = 64ul
false
true
EverCrypt.Hash.Incremental.Macros.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val blake2b_hash_len : FStar.UInt32.t
[]
EverCrypt.Hash.Incremental.Macros.blake2b_hash_len
{ "file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
FStar.UInt32.t
{ "end_col": 39, "end_line": 16, "start_col": 35, "start_line": 16 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let n = 128
let n =
false
null
false
128
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[ "total" ]
[]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64
false
true
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val n : Prims.int
[]
FStar.UInt128.n
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
Prims.int
{ "end_col": 11, "end_line": 25, "start_col": 8, "start_line": 25 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Plus_Hat = add
let op_Plus_Hat =
false
null
false
add
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.add" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Plus_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Plus_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 53, "end_line": 142, "start_col": 50, "start_line": 142 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Plus_Percent_Hat = add_mod
let op_Plus_Percent_Hat =
false
null
false
add_mod
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.add_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Plus_Percent_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Plus_Percent_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 65, "end_line": 144, "start_col": 58, "start_line": 144 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Greater_Hat = gt
let op_Greater_Hat =
false
null
false
gt
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.gt" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand inline_for_extraction noextract let op_Hat_Hat = logxor inline_for_extraction noextract let op_Bar_Hat = logor inline_for_extraction noextract let op_Less_Less_Hat = shift_left inline_for_extraction noextract let op_Greater_Greater_Hat = shift_right
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Greater_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
[]
FStar.UInt128.op_Greater_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
{ "end_col": 55, "end_line": 154, "start_col": 53, "start_line": 154 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Subtraction_Hat = sub
let op_Subtraction_Hat =
false
null
false
sub
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.sub" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Subtraction_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Subtraction_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 60, "end_line": 145, "start_col": 57, "start_line": 145 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Hat_Hat = logxor
let op_Hat_Hat =
false
null
false
logxor
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.logxor" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Hat_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Hat_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 55, "end_line": 149, "start_col": 49, "start_line": 149 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Plus_Question_Hat = add_underspec
let op_Plus_Question_Hat =
false
null
false
add_underspec
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.add_underspec" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *)
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Plus_Question_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Plus_Question_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 72, "end_line": 143, "start_col": 59, "start_line": 143 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Subtraction_Percent_Hat = sub_mod
let op_Subtraction_Percent_Hat =
false
null
false
sub_mod
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.sub_mod" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Subtraction_Percent_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Subtraction_Percent_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 72, "end_line": 147, "start_col": 65, "start_line": 147 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Greater_Greater_Hat = shift_right
let op_Greater_Greater_Hat =
false
null
false
shift_right
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.shift_right" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand inline_for_extraction noextract let op_Hat_Hat = logxor inline_for_extraction noextract let op_Bar_Hat = logor
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Greater_Greater_Hat : a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Greater_Greater_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 72, "end_line": 152, "start_col": 61, "start_line": 152 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Less_Equals_Hat = lte
let op_Less_Equals_Hat =
false
null
false
lte
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.lte" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand inline_for_extraction noextract let op_Hat_Hat = logxor inline_for_extraction noextract let op_Bar_Hat = logor inline_for_extraction noextract let op_Less_Less_Hat = shift_left inline_for_extraction noextract let op_Greater_Greater_Hat = shift_right inline_for_extraction noextract let op_Equals_Hat = eq inline_for_extraction noextract let op_Greater_Hat = gt inline_for_extraction noextract let op_Less_Hat = lt
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Less_Equals_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
[]
FStar.UInt128.op_Less_Equals_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
{ "end_col": 60, "end_line": 157, "start_col": 57, "start_line": 157 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Less_Less_Hat = shift_left
let op_Less_Less_Hat =
false
null
false
shift_left
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.shift_left" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand inline_for_extraction noextract let op_Hat_Hat = logxor
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Less_Less_Hat : a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Less_Less_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 65, "end_line": 151, "start_col": 55, "start_line": 151 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Amp_Hat = logand
let op_Amp_Hat =
false
null
false
logand
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.logand" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Amp_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Amp_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 55, "end_line": 148, "start_col": 49, "start_line": 148 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Less_Hat = lt
let op_Less_Hat =
false
null
false
lt
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.lt" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand inline_for_extraction noextract let op_Hat_Hat = logxor inline_for_extraction noextract let op_Bar_Hat = logor inline_for_extraction noextract let op_Less_Less_Hat = shift_left inline_for_extraction noextract let op_Greater_Greater_Hat = shift_right inline_for_extraction noextract let op_Equals_Hat = eq
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Less_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
[]
FStar.UInt128.op_Less_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
{ "end_col": 52, "end_line": 155, "start_col": 50, "start_line": 155 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Subtraction_Question_Hat = sub_underspec
let op_Subtraction_Question_Hat =
false
null
false
sub_underspec
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.sub_underspec" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Subtraction_Question_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Subtraction_Question_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 79, "end_line": 146, "start_col": 66, "start_line": 146 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Greater_Equals_Hat = gte
let op_Greater_Equals_Hat =
false
null
false
gte
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.gte" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand inline_for_extraction noextract let op_Hat_Hat = logxor inline_for_extraction noextract let op_Bar_Hat = logor inline_for_extraction noextract let op_Less_Less_Hat = shift_left inline_for_extraction noextract let op_Greater_Greater_Hat = shift_right inline_for_extraction noextract let op_Equals_Hat = eq inline_for_extraction noextract let op_Greater_Hat = gt
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Greater_Equals_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
[]
FStar.UInt128.op_Greater_Equals_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
{ "end_col": 63, "end_line": 156, "start_col": 60, "start_line": 156 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Equals_Hat = eq
let op_Equals_Hat =
false
null
false
eq
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.eq" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand inline_for_extraction noextract let op_Hat_Hat = logxor inline_for_extraction noextract let op_Bar_Hat = logor inline_for_extraction noextract let op_Less_Less_Hat = shift_left
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Equals_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
[]
FStar.UInt128.op_Equals_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool
{ "end_col": 54, "end_line": 153, "start_col": 52, "start_line": 153 }
Prims.Pure
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let op_Bar_Hat = logor
let op_Bar_Hat =
false
null
false
logor
{ "checked_file": "FStar.UInt128.fsti.checked", "dependencies": [ "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt128.fsti" }
[]
[ "FStar.UInt128.logor" ]
[]
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt128 open FStar.UInt open FStar.Mul module U32 = FStar.UInt32 module U64 = FStar.UInt64 noextract let n = 128 val t: (x:Type0{hasEq x}) [@@ noextract_to "krml"] val v (x:t) : Tot (uint_t n) [@@ noextract_to "krml"] val uint_to_t: x:uint_t n -> Pure t (requires True) (ensures (fun y -> v y = x)) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) val add: a:t -> b:t -> Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) val add_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) val add_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a + v b) % pow2 n = v c)) (* Subtraction primitives *) val sub: a:t -> b:t -> Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) val sub_underspec: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) val sub_mod: a:t -> b:t -> Pure t (requires True) (ensures (fun c -> (v a - v b) % pow2 n = v c)) (* Bitwise operators *) val logand: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logand (v a) (v b))) val logxor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logxor (v a) (v b))) val logor: a:t -> b:t -> Pure t (requires True) (ensures (fun r -> v r == logor (v a) (v b))) val lognot: a:t -> Pure t (requires True) (ensures (fun r -> v r == lognot (v a))) //This private primitive is used internally by the //compiler to translate bounded integer constants //with a desugaring-time check of the size of the number, //rather than an expensive verifiation check. //Since it is marked private, client programs cannot call it directly //Since it is marked unfold, it eagerly reduces, //eliminating the verification overhead of the wrapper private unfold let __uint_to_t (x:int) : Tot t = assume (fits x 128); uint_to_t x (* Shift operators *) val shift_left: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = ((v a * pow2 (UInt32.v s)) % pow2 n))) val shift_right: a:t -> s:UInt32.t -> Pure t (requires (U32.v s < n)) (ensures (fun c -> v c = (v a / (pow2 (UInt32.v s))))) (* Comparison operators *) val eq (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == eq #n (v a) (v b))) val gt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gt #n (v a) (v b))) val lt (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lt #n (v a) (v b))) val gte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == gte #n (v a) (v b))) val lte (a:t) (b:t) : Pure bool (requires True) (ensures (fun r -> r == lte #n (v a) (v b))) val eq_mask: a:t -> b:t -> Tot (c:t{(v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)}) val gte_mask: a:t -> b:t -> Tot (c:t{(v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)}) (* Casts *) val uint64_to_uint128: a:U64.t -> b:t{v b == U64.v a} val uint128_to_uint64: a:t -> b:U64.t{U64.v b == v a % pow2 64} (* To input / output constants *) (* TODO: assume these without implementations *) //val to_string: t -> Tot string //val of_string: string -> Tot t (* Infix notations *) inline_for_extraction noextract let op_Plus_Hat = add inline_for_extraction noextract let op_Plus_Question_Hat = add_underspec inline_for_extraction noextract let op_Plus_Percent_Hat = add_mod inline_for_extraction noextract let op_Subtraction_Hat = sub inline_for_extraction noextract let op_Subtraction_Question_Hat = sub_underspec inline_for_extraction noextract let op_Subtraction_Percent_Hat = sub_mod inline_for_extraction noextract let op_Amp_Hat = logand
false
false
FStar.UInt128.fsti
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val op_Bar_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
[]
FStar.UInt128.op_Bar_Hat
{ "file_name": "ulib/FStar.UInt128.fsti", "git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t
{ "end_col": 54, "end_line": 150, "start_col": 49, "start_line": 150 }