file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
EverCrypt.DRBG.fst | EverCrypt.DRBG.instantiate_sha1 | val instantiate_sha1 : instantiate_st SHA1 | val instantiate_sha1 : instantiate_st SHA1 | let instantiate_sha1 = mk_instantiate EverCrypt.HMAC.compute_sha1 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 142,
"start_col": 0,
"start_line": 142
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.instantiate_st Spec.Hash.Definitions.SHA1 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_instantiate",
"Spec.Hash.Definitions.SHA1",
"EverCrypt.HMAC.compute_sha1"
] | [] | false | false | false | true | false | let instantiate_sha1 =
| mk_instantiate EverCrypt.HMAC.compute_sha1 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.uninstantiate_sha1 | val uninstantiate_sha1 : uninstantiate_st SHA1 | val uninstantiate_sha1 : uninstantiate_st SHA1 | let uninstantiate_sha1 = mk_uninstantiate SHA1 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 281,
"start_col": 0,
"start_line": 281
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.uninstantiate_st Spec.Hash.Definitions.SHA1 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_uninstantiate",
"Spec.Hash.Definitions.SHA1"
] | [] | false | false | false | true | false | let uninstantiate_sha1 =
| mk_uninstantiate SHA1 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.create | val create: a:supported_alg -> ST (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 /\
invariant st h1 /\
freeable st h1) | val create: a:supported_alg -> ST (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 /\
invariant st h1 /\
freeable st h1) | let create a = create_in a HS.root | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 90,
"start_col": 0,
"start_line": 90
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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": 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
}
] | {
"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"
} | false | a: Hacl.HMAC_DRBG.supported_alg -> FStar.HyperStack.ST.ST (EverCrypt.DRBG.state a) | FStar.HyperStack.ST.ST | [] | [] | [
"Hacl.HMAC_DRBG.supported_alg",
"EverCrypt.DRBG.create_in",
"FStar.Monotonic.HyperHeap.root",
"EverCrypt.DRBG.state"
] | [] | false | true | false | false | false | let create a =
| create_in a HS.root | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.uninstantiate_sha2_256 | val uninstantiate_sha2_256: uninstantiate_st SHA2_256 | val uninstantiate_sha2_256: uninstantiate_st SHA2_256 | let uninstantiate_sha2_256 = mk_uninstantiate SHA2_256 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 282,
"start_col": 0,
"start_line": 282
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.uninstantiate_st Spec.Hash.Definitions.SHA2_256 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_uninstantiate",
"Spec.Hash.Definitions.SHA2_256"
] | [] | false | false | false | true | false | let uninstantiate_sha2_256 =
| mk_uninstantiate SHA2_256 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.reseed_sha2_512 | val reseed_sha2_512: reseed_st SHA2_512 | val reseed_sha2_512: reseed_st SHA2_512 | let reseed_sha2_512 = mk_reseed EverCrypt.HMAC.compute_sha2_512 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 195,
"start_col": 0,
"start_line": 195
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.reseed_st Spec.Hash.Definitions.SHA2_512 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_reseed",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.HMAC.compute_sha2_512"
] | [] | false | false | false | true | false | let reseed_sha2_512 =
| mk_reseed EverCrypt.HMAC.compute_sha2_512 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.instantiate | val instantiate: a:(Ghost.erased supported_alg) -> instantiate_st (Ghost.reveal a) | val instantiate: a:(Ghost.erased supported_alg) -> instantiate_st (Ghost.reveal a) | let instantiate a st personalization_string personalization_string_len =
match !*st with
| SHA1_s _ -> instantiate_sha1 st personalization_string personalization_string_len
| SHA2_256_s _ -> instantiate_sha2_256 st personalization_string personalization_string_len
| SHA2_384_s _ -> instantiate_sha2_384 st personalization_string personalization_string_len
| SHA2_512_s _ -> instantiate_sha2_512 st personalization_string personalization_string_len | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 93,
"end_line": 294,
"start_col": 0,
"start_line": 289
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512
let uninstantiate_sha1 = mk_uninstantiate SHA1
let uninstantiate_sha2_256 = mk_uninstantiate SHA2_256
let uninstantiate_sha2_384 = mk_uninstantiate SHA2_384
let uninstantiate_sha2_512 = mk_uninstantiate SHA2_512
/// Agile variants that dispatch dynamically to the appropriate monomorphic variants above | {
"checked_file": "/",
"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"
} | [
{
"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": 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
}
] | {
"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"
} | false | a: FStar.Ghost.erased Hacl.HMAC_DRBG.supported_alg
-> EverCrypt.DRBG.instantiate_st (FStar.Ghost.reveal a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.HMAC_DRBG.supported_alg",
"EverCrypt.DRBG.state",
"FStar.Ghost.reveal",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size_t",
"Hacl.HMAC_DRBG.state",
"Spec.Hash.Definitions.SHA1",
"EverCrypt.DRBG.instantiate_sha1",
"Prims.bool",
"Spec.Hash.Definitions.SHA2_256",
"EverCrypt.DRBG.instantiate_sha2_256",
"Spec.Hash.Definitions.SHA2_384",
"EverCrypt.DRBG.instantiate_sha2_384",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.DRBG.instantiate_sha2_512",
"EverCrypt.DRBG.state_s",
"Spec.HMAC_DRBG.supported_alg",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | false | let instantiate a st personalization_string personalization_string_len =
| match !*st with
| SHA1_s _ -> instantiate_sha1 st personalization_string personalization_string_len
| SHA2_256_s _ -> instantiate_sha2_256 st personalization_string personalization_string_len
| SHA2_384_s _ -> instantiate_sha2_384 st personalization_string personalization_string_len
| SHA2_512_s _ -> instantiate_sha2_512 st personalization_string personalization_string_len | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.generate_sha2_512 | val generate_sha2_512: generate_st SHA2_512 | val generate_sha2_512: generate_st SHA2_512 | let generate_sha2_512 = mk_generate EverCrypt.HMAC.compute_sha2_512 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 243,
"start_col": 0,
"start_line": 243
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.generate_st Spec.Hash.Definitions.SHA2_512 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_generate",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.HMAC.compute_sha2_512"
] | [] | false | false | false | true | false | let generate_sha2_512 =
| mk_generate EverCrypt.HMAC.compute_sha2_512 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.instantiate_sha2_512 | val instantiate_sha2_512: instantiate_st SHA2_512 | val instantiate_sha2_512: instantiate_st SHA2_512 | let instantiate_sha2_512 = mk_instantiate EverCrypt.HMAC.compute_sha2_512 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 145,
"start_col": 0,
"start_line": 145
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.instantiate_st Spec.Hash.Definitions.SHA2_512 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_instantiate",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.HMAC.compute_sha2_512"
] | [] | false | false | false | true | false | let instantiate_sha2_512 =
| mk_instantiate EverCrypt.HMAC.compute_sha2_512 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.reseed | val reseed: a:(Ghost.erased supported_alg) -> reseed_st (Ghost.reveal a) | val reseed: a:(Ghost.erased supported_alg) -> reseed_st (Ghost.reveal a) | let reseed a st additional_input additional_input_len =
match !*st with
| SHA1_s _ -> reseed_sha1 st additional_input additional_input_len
| SHA2_256_s _ -> reseed_sha2_256 st additional_input additional_input_len
| SHA2_384_s _ -> reseed_sha2_384 st additional_input additional_input_len
| SHA2_512_s _ -> reseed_sha2_512 st additional_input additional_input_len | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 301,
"start_col": 0,
"start_line": 296
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512
let uninstantiate_sha1 = mk_uninstantiate SHA1
let uninstantiate_sha2_256 = mk_uninstantiate SHA2_256
let uninstantiate_sha2_384 = mk_uninstantiate SHA2_384
let uninstantiate_sha2_512 = mk_uninstantiate SHA2_512
/// Agile variants that dispatch dynamically to the appropriate monomorphic variants above
let instantiate a st personalization_string personalization_string_len =
match !*st with
| SHA1_s _ -> instantiate_sha1 st personalization_string personalization_string_len
| SHA2_256_s _ -> instantiate_sha2_256 st personalization_string personalization_string_len
| SHA2_384_s _ -> instantiate_sha2_384 st personalization_string personalization_string_len
| SHA2_512_s _ -> instantiate_sha2_512 st personalization_string personalization_string_len | {
"checked_file": "/",
"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"
} | [
{
"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": 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
}
] | {
"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"
} | false | a: FStar.Ghost.erased Hacl.HMAC_DRBG.supported_alg
-> EverCrypt.DRBG.reseed_st (FStar.Ghost.reveal a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.HMAC_DRBG.supported_alg",
"EverCrypt.DRBG.state",
"FStar.Ghost.reveal",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size_t",
"Hacl.HMAC_DRBG.state",
"Spec.Hash.Definitions.SHA1",
"EverCrypt.DRBG.reseed_sha1",
"Prims.bool",
"Spec.Hash.Definitions.SHA2_256",
"EverCrypt.DRBG.reseed_sha2_256",
"Spec.Hash.Definitions.SHA2_384",
"EverCrypt.DRBG.reseed_sha2_384",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.DRBG.reseed_sha2_512",
"EverCrypt.DRBG.state_s",
"Spec.HMAC_DRBG.supported_alg",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | false | let reseed a st additional_input additional_input_len =
| match !*st with
| SHA1_s _ -> reseed_sha1 st additional_input additional_input_len
| SHA2_256_s _ -> reseed_sha2_256 st additional_input additional_input_len
| SHA2_384_s _ -> reseed_sha2_384 st additional_input additional_input_len
| SHA2_512_s _ -> reseed_sha2_512 st additional_input additional_input_len | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.instantiate_sha2_384 | val instantiate_sha2_384: instantiate_st SHA2_384 | val instantiate_sha2_384: instantiate_st SHA2_384 | let instantiate_sha2_384 = mk_instantiate EverCrypt.HMAC.compute_sha2_384 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 144,
"start_col": 0,
"start_line": 144
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.instantiate_st Spec.Hash.Definitions.SHA2_384 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_instantiate",
"Spec.Hash.Definitions.SHA2_384",
"EverCrypt.HMAC.compute_sha2_384"
] | [] | false | false | false | true | false | let instantiate_sha2_384 =
| mk_instantiate EverCrypt.HMAC.compute_sha2_384 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.uninstantiate_sha2_384 | val uninstantiate_sha2_384: uninstantiate_st SHA2_384 | val uninstantiate_sha2_384: uninstantiate_st SHA2_384 | let uninstantiate_sha2_384 = mk_uninstantiate SHA2_384 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 283,
"start_col": 0,
"start_line": 283
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512
let uninstantiate_sha1 = mk_uninstantiate SHA1 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.uninstantiate_st Spec.Hash.Definitions.SHA2_384 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_uninstantiate",
"Spec.Hash.Definitions.SHA2_384"
] | [] | false | false | false | true | false | let uninstantiate_sha2_384 =
| mk_uninstantiate SHA2_384 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.generate | val generate: a:(Ghost.erased supported_alg) -> generate_st (Ghost.reveal a) | val generate: a:(Ghost.erased supported_alg) -> generate_st (Ghost.reveal a) | let generate a output st n additional_input additional_input_len =
match !*st with
| SHA1_s _ -> generate_sha1 output st n additional_input additional_input_len
| SHA2_256_s _ -> generate_sha2_256 output st n additional_input additional_input_len
| SHA2_384_s _ -> generate_sha2_384 output st n additional_input additional_input_len
| SHA2_512_s _ -> generate_sha2_512 output st n additional_input additional_input_len | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 308,
"start_col": 0,
"start_line": 303
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512
let uninstantiate_sha1 = mk_uninstantiate SHA1
let uninstantiate_sha2_256 = mk_uninstantiate SHA2_256
let uninstantiate_sha2_384 = mk_uninstantiate SHA2_384
let uninstantiate_sha2_512 = mk_uninstantiate SHA2_512
/// Agile variants that dispatch dynamically to the appropriate monomorphic variants above
let instantiate a st personalization_string personalization_string_len =
match !*st with
| SHA1_s _ -> instantiate_sha1 st personalization_string personalization_string_len
| SHA2_256_s _ -> instantiate_sha2_256 st personalization_string personalization_string_len
| SHA2_384_s _ -> instantiate_sha2_384 st personalization_string personalization_string_len
| SHA2_512_s _ -> instantiate_sha2_512 st personalization_string personalization_string_len
let reseed a st additional_input additional_input_len =
match !*st with
| SHA1_s _ -> reseed_sha1 st additional_input additional_input_len
| SHA2_256_s _ -> reseed_sha2_256 st additional_input additional_input_len
| SHA2_384_s _ -> reseed_sha2_384 st additional_input additional_input_len
| SHA2_512_s _ -> reseed_sha2_512 st additional_input additional_input_len | {
"checked_file": "/",
"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"
} | [
{
"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": 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
}
] | {
"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"
} | false | a: FStar.Ghost.erased Hacl.HMAC_DRBG.supported_alg
-> EverCrypt.DRBG.generate_st (FStar.Ghost.reveal a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.HMAC_DRBG.supported_alg",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"EverCrypt.DRBG.state",
"FStar.Ghost.reveal",
"Lib.IntTypes.size_t",
"Hacl.HMAC_DRBG.state",
"Spec.Hash.Definitions.SHA1",
"EverCrypt.DRBG.generate_sha1",
"Prims.bool",
"Spec.Hash.Definitions.SHA2_256",
"EverCrypt.DRBG.generate_sha2_256",
"Spec.Hash.Definitions.SHA2_384",
"EverCrypt.DRBG.generate_sha2_384",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.DRBG.generate_sha2_512",
"EverCrypt.DRBG.state_s",
"Spec.HMAC_DRBG.supported_alg",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | false | let generate a output st n additional_input additional_input_len =
| match !*st with
| SHA1_s _ -> generate_sha1 output st n additional_input additional_input_len
| SHA2_256_s _ -> generate_sha2_256 output st n additional_input additional_input_len
| SHA2_384_s _ -> generate_sha2_384 output st n additional_input additional_input_len
| SHA2_512_s _ -> generate_sha2_512 output st n additional_input additional_input_len | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.uninstantiate_sha2_512 | val uninstantiate_sha2_512: uninstantiate_st SHA2_512 | val uninstantiate_sha2_512: uninstantiate_st SHA2_512 | let uninstantiate_sha2_512 = mk_uninstantiate SHA2_512 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 284,
"start_col": 0,
"start_line": 284
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512
let uninstantiate_sha1 = mk_uninstantiate SHA1
let uninstantiate_sha2_256 = mk_uninstantiate SHA2_256 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.uninstantiate_st Spec.Hash.Definitions.SHA2_512 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_uninstantiate",
"Spec.Hash.Definitions.SHA2_512"
] | [] | false | false | false | true | false | let uninstantiate_sha2_512 =
| mk_uninstantiate SHA2_512 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.generate_sha2_256 | val generate_sha2_256: generate_st SHA2_256 | val generate_sha2_256: generate_st SHA2_256 | let generate_sha2_256 = mk_generate EverCrypt.HMAC.compute_sha2_256 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 241,
"start_col": 0,
"start_line": 241
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.generate_st Spec.Hash.Definitions.SHA2_256 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_generate",
"Spec.Hash.Definitions.SHA2_256",
"EverCrypt.HMAC.compute_sha2_256"
] | [] | false | false | false | true | false | let generate_sha2_256 =
| mk_generate EverCrypt.HMAC.compute_sha2_256 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.reseed_sha2_384 | val reseed_sha2_384: reseed_st SHA2_384 | val reseed_sha2_384: reseed_st SHA2_384 | let reseed_sha2_384 = mk_reseed EverCrypt.HMAC.compute_sha2_384 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 194,
"start_col": 0,
"start_line": 194
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | EverCrypt.DRBG.reseed_st Spec.Hash.Definitions.SHA2_384 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.DRBG.mk_reseed",
"Spec.Hash.Definitions.SHA2_384",
"EverCrypt.HMAC.compute_sha2_384"
] | [] | false | false | false | true | false | let reseed_sha2_384 =
| mk_reseed EverCrypt.HMAC.compute_sha2_384 | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.uninstantiate | val uninstantiate: a:(Ghost.erased supported_alg) -> uninstantiate_st (Ghost.reveal a) | val uninstantiate: a:(Ghost.erased supported_alg) -> uninstantiate_st (Ghost.reveal a) | let uninstantiate a st =
match !* st with
| SHA1_s _ -> uninstantiate_sha1 st
| SHA2_256_s _ -> uninstantiate_sha2_256 st
| SHA2_384_s _ -> uninstantiate_sha2_384 st
| SHA2_512_s _ -> uninstantiate_sha2_512 st | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 315,
"start_col": 0,
"start_line": 310
} | 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
val mk_uninstantiate: a:supported_alg -> uninstantiate_st a
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
(** @type: true
*)
val uninstantiate_sha1 : uninstantiate_st SHA1
(** @type: true
*)
val uninstantiate_sha2_256: uninstantiate_st SHA2_256
(** @type: true
*)
val uninstantiate_sha2_384: uninstantiate_st SHA2_384
(** @type: true
*)
val uninstantiate_sha2_512: uninstantiate_st SHA2_512
let uninstantiate_sha1 = mk_uninstantiate SHA1
let uninstantiate_sha2_256 = mk_uninstantiate SHA2_256
let uninstantiate_sha2_384 = mk_uninstantiate SHA2_384
let uninstantiate_sha2_512 = mk_uninstantiate SHA2_512
/// Agile variants that dispatch dynamically to the appropriate monomorphic variants above
let instantiate a st personalization_string personalization_string_len =
match !*st with
| SHA1_s _ -> instantiate_sha1 st personalization_string personalization_string_len
| SHA2_256_s _ -> instantiate_sha2_256 st personalization_string personalization_string_len
| SHA2_384_s _ -> instantiate_sha2_384 st personalization_string personalization_string_len
| SHA2_512_s _ -> instantiate_sha2_512 st personalization_string personalization_string_len
let reseed a st additional_input additional_input_len =
match !*st with
| SHA1_s _ -> reseed_sha1 st additional_input additional_input_len
| SHA2_256_s _ -> reseed_sha2_256 st additional_input additional_input_len
| SHA2_384_s _ -> reseed_sha2_384 st additional_input additional_input_len
| SHA2_512_s _ -> reseed_sha2_512 st additional_input additional_input_len
let generate a output st n additional_input additional_input_len =
match !*st with
| SHA1_s _ -> generate_sha1 output st n additional_input additional_input_len
| SHA2_256_s _ -> generate_sha2_256 output st n additional_input additional_input_len
| SHA2_384_s _ -> generate_sha2_384 output st n additional_input additional_input_len
| SHA2_512_s _ -> generate_sha2_512 output st n additional_input additional_input_len | {
"checked_file": "/",
"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"
} | [
{
"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": 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
}
] | {
"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"
} | false | a: FStar.Ghost.erased Hacl.HMAC_DRBG.supported_alg
-> EverCrypt.DRBG.uninstantiate_st (FStar.Ghost.reveal a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Hacl.HMAC_DRBG.supported_alg",
"EverCrypt.DRBG.state",
"FStar.Ghost.reveal",
"Hacl.HMAC_DRBG.state",
"Spec.Hash.Definitions.SHA1",
"EverCrypt.DRBG.uninstantiate_sha1",
"Prims.unit",
"Spec.Hash.Definitions.SHA2_256",
"EverCrypt.DRBG.uninstantiate_sha2_256",
"Spec.Hash.Definitions.SHA2_384",
"EverCrypt.DRBG.uninstantiate_sha2_384",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.DRBG.uninstantiate_sha2_512",
"EverCrypt.DRBG.state_s",
"Spec.HMAC_DRBG.supported_alg",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | false | let uninstantiate a st =
| match !*st with
| SHA1_s _ -> uninstantiate_sha1 st
| SHA2_256_s _ -> uninstantiate_sha2_256 st
| SHA2_384_s _ -> uninstantiate_sha2_384 st
| SHA2_512_s _ -> uninstantiate_sha2_512 st | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.mk_uninstantiate | val mk_uninstantiate: a:supported_alg -> uninstantiate_st a | val mk_uninstantiate: a:supported_alg -> uninstantiate_st a | 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 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 263,
"start_col": 0,
"start_line": 249
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Hacl.HMAC_DRBG.supported_alg -> EverCrypt.DRBG.uninstantiate_st a | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct10 | val compute_gen_elim_nondep_correct10 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10]) | val compute_gen_elim_nondep_correct10 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10]) | let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 659,
"start_col": 0,
"start_line": 639
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i0: Steel.ST.GenElim1.Base.gen_elim_i ->
t1: Type ->
t2: Type ->
t3: Type ->
t4: Type ->
t5: Type ->
t6: Type ->
t7: Type ->
t8: Type ->
t9: Type ->
t10: Type
-> Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t i0
[t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.Base.curried_function_type",
"Prims.Cons",
"Prims.Nil",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.gen_elim_nondep_p",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a'",
"Steel.ST.GenElim1.rewrite_with_trefl",
"FStar.Universe.raise_val",
"Steel.ST.GenElim1.Base.compute_uncurry",
"Steel.ST.GenElim1.Base.compute_gen_elim_p'",
"Steel.ST.Util.elim_pure",
"FStar.Pervasives.Native.tuple10",
"FStar.Pervasives.Native.Mktuple10",
"Steel.ST.GenElim1.elim_exists'",
"Steel.Effect.Common.VStar",
"Steel.ST.Util.pure",
"Steel.ST.Util.exists_",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t"
] | [] | false | false | false | false | false | let compute_gen_elim_nondep_correct10 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10]) =
| fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _)
(exists_ (fun x1 ->
exists_ (fun x2 ->
exists_ (fun x3 ->
exists_ (fun x4 ->
exists_ (fun x5 ->
exists_ (fun x6 ->
exists_ (fun x7 ->
exists_ (fun x8 ->
exists_ (fun x9 ->
exists_ (fun x10 ->
(q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10
(U.raise_val ()))
`star`
(pure (post x1 x2 x3 x4 x5 x6 x7
x8 x9 x10 (U.raise_val ())
)))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ()))
(compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.alloca | 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) | 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 =
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 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 78,
"start_col": 0,
"start_line": 70
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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": 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
}
] | {
"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"
} | false | a: Hacl.HMAC_DRBG.supported_alg -> FStar.HyperStack.ST.StackInline (EverCrypt.DRBG.state a) | FStar.HyperStack.ST.StackInline | [] | [] | [
"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"
] | [] | false | true | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_der_length_payload_kind_weak | val parse_der_length_payload_kind_weak:parser_kind | val parse_der_length_payload_kind_weak:parser_kind | let parse_der_length_payload_kind_weak : parser_kind =
strong_parser_kind 0 126 None | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 31,
"end_line": 215,
"start_col": 0,
"start_line": 214
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | LowParse.Spec.Base.parser_kind | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.strong_parser_kind",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Base.parser_kind_metadata_some"
] | [] | false | false | false | true | false | let parse_der_length_payload_kind_weak:parser_kind =
| strong_parser_kind 0 126 None | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_der_length_weak_kind | val parse_der_length_weak_kind:parser_kind | val parse_der_length_weak_kind:parser_kind | let parse_der_length_weak_kind : parser_kind = and_then_kind parse_u8_kind parse_der_length_payload_kind_weak | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 109,
"end_line": 218,
"start_col": 0,
"start_line": 218
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | LowParse.Spec.Base.parser_kind | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Int.parse_u8_kind",
"LowParse.Spec.DER.parse_der_length_payload_kind_weak"
] | [] | false | false | false | true | false | let parse_der_length_weak_kind:parser_kind =
| and_then_kind parse_u8_kind parse_der_length_payload_kind_weak | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_tag_cond | val parse_bounded_der_length_tag_cond (min: der_length_t) (max: der_length_t{min <= max}) (x: U8.t)
: Tot bool | 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
= let len = der_length_payload_size_of_tag x in der_length_payload_size min <= len && len <= der_length_payload_size max | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 120,
"end_line": 245,
"start_col": 0,
"start_line": 240
} | 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 }) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
min: LowParse.Spec.DER.der_length_t ->
max: LowParse.Spec.DER.der_length_t{min <= max} ->
x: FStar.UInt8.t
-> Prims.bool | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_kind | val parse_bounded_der_length_kind (min: der_length_t) (max: der_length_t{min <= max})
: Tot parser_kind | 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
= and_then_kind
(parse_filter_kind parse_u8_kind)
(parse_bounded_der_length_payload_kind min max) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 51,
"end_line": 274,
"start_col": 0,
"start_line": 268
} | 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))) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max}
-> LowParse.Spec.Base.parser_kind | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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) | false |
EverCrypt.DRBG.fst | EverCrypt.DRBG.create_in | 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) | 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 =
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 | {
"file_name": "providers/evercrypt/fst/EverCrypt.DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 88,
"start_col": 0,
"start_line": 80
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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": 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
}
] | {
"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"
} | false | a: Hacl.HMAC_DRBG.supported_alg -> r: FStar.Monotonic.HyperHeap.rid
-> FStar.HyperStack.ST.ST (EverCrypt.DRBG.state a) | FStar.HyperStack.ST.ST | [] | [] | [
"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"
] | [] | false | true | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.log256_le | val log256_le
(x1 x2: nat)
: Lemma
(requires (0 < x1 /\ x1 <= x2))
(ensures (log256 x1 <= log256 x2)) | val log256_le
(x1 x2: nat)
: Lemma
(requires (0 < x1 /\ x1 <= x2))
(ensures (log256 x1 <= log256 x2)) | let log256_le
x1
x2
= Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 58,
"end_line": 43,
"start_col": 0,
"start_line": 40
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"LowParse.Math.pow2_lt_recip",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"LowParse.Spec.DER.log256",
"Prims.unit"
] | [] | true | false | true | false | false | let log256_le x1 x2 =
| Math.pow2_lt_recip (8 * (log256 x1 - 1)) (8 * log256 x2) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.log256 | val log256
(x: nat { x > 0 })
: Tot (y: nat { y > 0 /\ pow2 (8 * (y - 1)) <= x /\ x < pow2 (8 * y)}) | 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)})
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 32,
"start_col": 0,
"start_line": 21
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: Prims.nat{x > 0}
-> y: Prims.nat{y > 0 /\ Prims.pow2 (8 * (y - 1)) <= x /\ x < Prims.pow2 (8 * y)} | Prims.Tot | [
"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"
] | [
"recursion"
] | false | false | false | false | 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
let n = log256 (x / 256) in
Math.pow2_plus (8 * (n - 1)) 8;
Math.pow2_plus (8 * n) 8;
n + 1 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_be_int_injective | val synth_be_int_injective (len: nat)
: Lemma (synth_injective (synth_be_int len)) [SMTPat (synth_injective (synth_be_int len))] | 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))]
=
synth_injective_intro' (synth_be_int len) (fun (x x' : Seq.lseq byte len) ->
E.be_to_n_inj x x'
) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 73,
"start_col": 0,
"start_line": 65
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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))] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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: Seq.lseq byte len) (x': Seq.lseq byte len) -> E.be_to_n_inj x x') | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.log256_unique | 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)) | 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
= Math.pow2_lt_recip (8 * (y - 1)) (8 * log256 x);
Math.pow2_lt_recip (8 * (log256 x - 1)) (8 * y) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 49,
"end_line": 38,
"start_col": 0,
"start_line": 34
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"LowParse.Math.pow2_lt_recip",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"LowParse.Spec.DER.log256",
"Prims.unit"
] | [] | true | false | true | false | 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) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_be_int | val synth_be_int (len: nat) (b: Seq.lseq byte len) : Tot (lint len) | 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)
= E.lemma_be_to_n_is_bounded b;
E.be_to_n b | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 63,
"start_col": 0,
"start_line": 58
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | len: Prims.nat -> b: FStar.Seq.Properties.lseq LowParse.Bytes.byte len -> LowParse.Spec.DER.lint len | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_der_length_weak | val parse_der_length_weak:parser parse_der_length_weak_kind der_length_t | 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
= parse_tagged_union
parse_u8
tag_of_der_length
(fun x -> weaken parse_der_length_payload_kind_weak (parse_der_length_payload x)) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 85,
"end_line": 224,
"start_col": 0,
"start_line": 220
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | LowParse.Spec.Base.parser LowParse.Spec.DER.parse_der_length_weak_kind
LowParse.Spec.DER.der_length_t | Prims.Tot | [
"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"
] | [] | false | false | false | true | 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)) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_payload_kind | val parse_bounded_der_length_payload_kind (min: der_length_t) (max: der_length_t{min <= max})
: Tot parser_kind | 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 =
[@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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 85,
"end_line": 232,
"start_col": 0,
"start_line": 227
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | min: LowParse.Spec.DER.der_length_t -> max: LowParse.Spec.DER.der_length_t{min <= max}
-> LowParse.Spec.Base.parser_kind | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.tag_of_bounded_der_length | 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}) | 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 } )
= [@inline_let]
let _ = der_length_payload_size_le min x; der_length_payload_size_le x max in
tag_of_der_length x | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 21,
"end_line": 255,
"start_col": 0,
"start_line": 248
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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} | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_payload | 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)) | 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))
= 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))) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 156,
"end_line": 265,
"start_col": 0,
"start_line": 257
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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))) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_weak | 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)) | 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))
= 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)) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 94,
"end_line": 372,
"start_col": 0,
"start_line": 366
} | 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 () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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)) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_eq | 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)) | 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))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 9,
"end_line": 422,
"start_col": 0,
"start_line": 404
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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
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) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length | 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)) | 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))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 46,
"end_line": 283,
"start_col": 0,
"start_line": 276
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_be_int_recip | val synth_be_int_recip (len: nat) (x: lint len) : GTot (b : Seq.lseq byte len) | 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)
= E.n_to_be len x | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 473,
"start_col": 0,
"start_line": 469
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | len: Prims.nat -> x: LowParse.Spec.DER.lint len
-> Prims.GTot (FStar.Seq.Properties.lseq LowParse.Bytes.byte len) | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.nat",
"LowParse.Spec.DER.lint",
"FStar.Endianness.n_to_be",
"FStar.Seq.Properties.lseq",
"LowParse.Bytes.byte"
] | [] | false | false | false | false | false | let synth_be_int_recip (len: nat) (x: lint len) : GTot (b : Seq.lseq byte len) =
| E.n_to_be len x | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_unfold_aux | 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)) | 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
))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 334,
"start_col": 0,
"start_line": 312
} | 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' | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.der_length_max_eq | val der_length_max_eq : squash (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 =
assert_norm (der_length_max == pow2 (8 * 126) - 1) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 19,
"start_col": 0,
"start_line": 18
} | 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 (`()))) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | Prims.squash (LowParse.Spec.DER.der_length_max == Prims.pow2 (8 * 126) - 1) | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"LowParse.Spec.DER.der_length_max",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.Mul.op_Star"
] | [] | false | false | true | false | false | let der_length_max_eq =
| assert_norm (der_length_max == pow2 (8 * 126) - 1) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_der_length_129 | 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) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 8,
"end_line": 85,
"start_col": 0,
"start_line": 75
} | 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'
) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_unfold | 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)) | 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
))
= 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 () | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 11,
"end_line": 364,
"start_col": 0,
"start_line": 336
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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' | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.tag_of_der_length_eq_129_eta | 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) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 148,
"end_line": 532,
"start_col": 0,
"start_line": 531
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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) | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_der_length_129_recip | 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}) | 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})
= tag_of_der_length_eq_129 y;
U8.uint_to_t y | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 16,
"end_line": 467,
"start_col": 0,
"start_line": 462
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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}) | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.der_length_payload_size_le | 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)) | 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
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 53,
"end_line": 56,
"start_col": 0,
"start_line": 45
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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
) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_weak_unfold | 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)) | 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
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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 9,
"end_line": 402,
"start_col": 0,
"start_line": 374
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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
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)) =
| 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.tag_of_der_length_invalid_eta | 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) | 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 92,
"end_line": 529,
"start_col": 0,
"start_line": 528
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.tag_of_der_length_lt_128_eta | 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) | 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 99,
"end_line": 526,
"start_col": 0,
"start_line": 525
} | 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)
()
) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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) | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length_payload_unfold | 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)) | 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
))
=
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' | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 16,
"end_line": 310,
"start_col": 0,
"start_line": 287
} | 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 *) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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'))) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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' | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.serialize_bounded_der_length | val serialize_bounded_der_length (min: der_length_t) (max: der_length_t{min <= max})
: Tot (serializer (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))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 715,
"start_col": 0,
"start_line": 707
} | 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})))
() | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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) | false |
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha2_256_hash_len | val sha2_256_hash_len : FStar.UInt32.t | let sha2_256_hash_len = 32ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 8,
"start_col": 12,
"start_line": 8
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha2_256_hash_len =
| 32ul | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.serialize_der_length_weak | val serialize_der_length_weak:serializer parse_der_length_weak | val serialize_der_length_weak:serializer parse_der_length_weak | 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)) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 99,
"end_line": 573,
"start_col": 0,
"start_line": 569
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | LowParse.Spec.Base.serializer LowParse.Spec.DER.parse_der_length_weak | Prims.Tot | [
"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"
] | [] | false | false | false | true | 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)) | false |
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.md5_hash_len | val md5_hash_len : FStar.UInt32.t | let md5_hash_len = 16ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 5,
"start_col": 12,
"start_line": 5
} | // Separate module because -no-prefix
module EverCrypt.Hash.Incremental.Macros | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let md5_hash_len =
| 16ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha1_hash_len | val sha1_hash_len : FStar.UInt32.t | let sha1_hash_len = 20ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 6,
"start_col": 12,
"start_line": 6
} | // Separate module because -no-prefix
module EverCrypt.Hash.Incremental.Macros
(* These definitions for the benefits of C clients. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha1_hash_len =
| 20ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha2_512_hash_len | val sha2_512_hash_len : FStar.UInt32.t | let sha2_512_hash_len = 64ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 10,
"start_col": 12,
"start_line": 10
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha2_512_hash_len =
| 64ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha2_384_hash_len | val sha2_384_hash_len : FStar.UInt32.t | let sha2_384_hash_len = 48ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 9,
"start_col": 12,
"start_line": 9
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha2_384_hash_len =
| 48ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha2_224_hash_len | val sha2_224_hash_len : FStar.UInt32.t | let sha2_224_hash_len = 28ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 7,
"start_col": 12,
"start_line": 7
} | // Separate module because -no-prefix
module EverCrypt.Hash.Incremental.Macros
(* These definitions for the benefits of C clients. *)
[@ CMacro ] let md5_hash_len = 16ul | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha2_224_hash_len =
| 28ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha3_256_hash_len | val sha3_256_hash_len : FStar.UInt32.t | let sha3_256_hash_len = 32ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 12,
"start_col": 12,
"start_line": 12
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha3_256_hash_len =
| 32ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha3_384_hash_len | val sha3_384_hash_len : FStar.UInt32.t | let sha3_384_hash_len = 48ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 13,
"start_col": 12,
"start_line": 13
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha3_384_hash_len =
| 48ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha3_224_hash_len | val sha3_224_hash_len : FStar.UInt32.t | let sha3_224_hash_len = 28ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 11,
"start_col": 12,
"start_line": 11
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha3_224_hash_len =
| 28ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.blake2s_hash_len | val blake2s_hash_len : FStar.UInt32.t | let blake2s_hash_len = 32ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 15,
"start_col": 12,
"start_line": 15
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let blake2s_hash_len =
| 32ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.sha3_512_hash_len | val sha3_512_hash_len : FStar.UInt32.t | let sha3_512_hash_len = 64ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 14,
"start_col": 12,
"start_line": 14
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let sha3_512_hash_len =
| 64ul | false |
|
EverCrypt.Hash.Incremental.Macros.fst | EverCrypt.Hash.Incremental.Macros.blake2b_hash_len | val blake2b_hash_len : FStar.UInt32.t | let blake2b_hash_len = 64ul | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.Macros.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 16,
"start_col": 12,
"start_line": 16
} | // 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 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.Macros.fst"
} | [
{
"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
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let blake2b_hash_len =
| 64ul | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_der_length_greater | 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) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 100,
"start_col": 0,
"start_line": 87
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.serialize_der_length_payload_greater | 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)) | 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)
()
) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 523,
"start_col": 0,
"start_line": 498
} | 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))
= () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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)
()) | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.tag_of_der_length_invalid | 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) | 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)
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 448,
"start_col": 0,
"start_line": 438
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
FStar.UInt128.fsti | FStar.UInt128.op_Plus_Hat | val op_Plus_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Plus_Hat = add | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 142,
"start_col": 32,
"start_line": 142
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.add"
] | [] | false | false | false | false | false | let op_Plus_Hat =
| add | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_der_length_payload | val parse_der_length_payload (x: U8.t)
: Tot (parser (parse_der_length_payload_kind x) (refine_with_tag tag_of_der_length x)) | 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))
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 133,
"start_col": 0,
"start_line": 102
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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
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)) | false |
FStar.UInt128.fsti | FStar.UInt128.op_Plus_Percent_Hat | val op_Plus_Percent_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Plus_Percent_Hat = add_mod | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 144,
"start_col": 32,
"start_line": 144
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.add_mod"
] | [] | false | false | false | false | false | let op_Plus_Percent_Hat =
| add_mod | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.serialize_bounded_der_length_weak | 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)) | 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))
= 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})))
() | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 705,
"start_col": 0,
"start_line": 693
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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})))
() | false |
FStar.UInt128.fsti | FStar.UInt128.n | val n : Prims.int | let n = 128 | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let n =
| 128 | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Subtraction_Percent_Hat | val op_Subtraction_Percent_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Subtraction_Percent_Hat = sub_mod | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 147,
"start_col": 32,
"start_line": 147
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.sub_mod"
] | [] | false | false | false | false | false | let op_Subtraction_Percent_Hat =
| sub_mod | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Subtraction_Question_Hat | val op_Subtraction_Question_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Subtraction_Question_Hat = sub_underspec | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 79,
"end_line": 146,
"start_col": 32,
"start_line": 146
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.sub_underspec"
] | [] | false | false | false | false | false | let op_Subtraction_Question_Hat =
| sub_underspec | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_der_length_payload32 | 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)) | 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))
= parse_der_length_payload x `parse_synth` synth_der_length_payload32 x | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 71,
"end_line": 827,
"start_col": 0,
"start_line": 824
} | 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
) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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) | false |
FStar.UInt128.fsti | FStar.UInt128.op_Plus_Question_Hat | val op_Plus_Question_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Plus_Question_Hat = add_underspec | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 143,
"start_col": 32,
"start_line": 143
} | (*
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 *) | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.add_underspec"
] | [] | false | false | false | false | false | let op_Plus_Question_Hat =
| add_underspec | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Subtraction_Hat | val op_Subtraction_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Subtraction_Hat = sub | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 145,
"start_col": 32,
"start_line": 145
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.sub"
] | [] | false | false | false | false | false | let op_Subtraction_Hat =
| sub | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.tag_of_der_length_lt_128 | 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))) | 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)))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 436,
"start_col": 0,
"start_line": 426
} | 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 *) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
FStar.UInt128.fsti | FStar.UInt128.op_Amp_Hat | val op_Amp_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Amp_Hat = logand | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 148,
"start_col": 32,
"start_line": 148
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.logand"
] | [] | false | false | false | false | false | let op_Amp_Hat =
| logand | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Bar_Hat | val op_Bar_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Bar_Hat = logor | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 150,
"start_col": 32,
"start_line": 150
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.logor"
] | [] | false | false | false | false | false | let op_Bar_Hat =
| logor | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Less_Less_Hat | val op_Less_Less_Hat : a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t | let op_Less_Less_Hat = shift_left | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 151,
"start_col": 32,
"start_line": 151
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.shift_left"
] | [] | false | false | false | false | false | let op_Less_Less_Hat =
| shift_left | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Hat_Hat | val op_Hat_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | let op_Hat_Hat = logxor | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 149,
"start_col": 32,
"start_line": 149
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.logxor"
] | [] | false | false | false | false | false | let op_Hat_Hat =
| logxor | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Less_Hat | val op_Less_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | let op_Less_Hat = lt | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 155,
"start_col": 32,
"start_line": 155
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | Prims.Pure | [] | [] | [
"FStar.UInt128.lt"
] | [] | false | false | false | false | false | let op_Less_Hat =
| lt | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Greater_Hat | val op_Greater_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | let op_Greater_Hat = gt | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 154,
"start_col": 32,
"start_line": 154
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module 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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | Prims.Pure | [] | [] | [
"FStar.UInt128.gt"
] | [] | false | false | false | false | false | let op_Greater_Hat =
| gt | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Equals_Hat | val op_Equals_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | let op_Equals_Hat = eq | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 153,
"start_col": 32,
"start_line": 153
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | Prims.Pure | [] | [] | [
"FStar.UInt128.eq"
] | [] | false | false | false | false | false | let op_Equals_Hat =
| eq | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Greater_Greater_Hat | val op_Greater_Greater_Hat : a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t | let op_Greater_Greater_Hat = shift_right | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 152,
"start_col": 32,
"start_line": 152
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt128.t | Prims.Pure | [] | [] | [
"FStar.UInt128.shift_right"
] | [] | false | false | false | false | false | let op_Greater_Greater_Hat =
| shift_right | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.be_int_of_bounded_integer_injective | 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))] | 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))] // 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 42,
"end_line": 849,
"start_col": 0,
"start_line": 840
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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))
] | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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))] =
| 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) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_bounded_der_length32 | 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) | 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)
= U32.uint_to_t x | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 927,
"start_col": 0,
"start_line": 922
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.be_int_of_bounded_integer | val be_int_of_bounded_integer (len: integer_size) (x: nat{x < pow2 (8 * len)})
: GTot (bounded_integer len) | 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)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 838,
"start_col": 0,
"start_line": 829
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | len: LowParse.Spec.BoundedInt.integer_size -> x: Prims.nat{x < Prims.pow2 (8 * len)}
-> Prims.GTot (LowParse.Spec.BoundedInt.bounded_integer len) | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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 | false |
Pulse.Typing.Metatheory.Base.fsti | Pulse.Typing.Metatheory.Base.renaming | val renaming : x: Pulse.Syntax.Base.var -> y: Pulse.Syntax.Base.var -> Prims.list Pulse.Syntax.Naming.subst_elt | let renaming x y = [NT x (tm_var {nm_index=y; nm_ppname=ppname_default})] | {
"file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 73,
"end_line": 85,
"start_col": 0,
"start_line": 85
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Typing.Metatheory.Base
open Pulse.Syntax
open Pulse.Syntax.Naming
open Pulse.Typing
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
val admit_comp_typing (g:env) (c:comp_st)
: comp_typing_u g c
module RT = FStar.Reflection.Typing
let rt_equiv_typing (#g:_) (#t0 #t1:_) (d:RT.equiv g t0 t1)
(#k:_)
(d1:Ghost.erased (RT.tot_typing g t0 k))
: Ghost.erased (RT.tot_typing g t1 k)
= admit()
val st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c})
(_:st_typing g t c)
: (u:Ghost.erased universe & universe_of g (comp_res c) u)
let inames_of_comp_st (c:comp_st) =
match c with
| C_STAtomic _ _ _ -> comp_inames c
| _ -> tm_emp_inames
let iname_typing (g:env) (c:comp_st) = tot_typing g (inames_of_comp_st c) tm_inames
val st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st)
(d: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) & iname_typing g 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)
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module C = FStar.Stubs.TypeChecker.Core
open FStar.Ghost
val typing_correctness
(#g:R.env)
(#t:R.term)
(#ty:R.typ)
(#eff:_)
(_:erased (RT.typing g t (eff, ty)))
: erased (u:R.universe & RT.typing g ty (C.E_Total, RT.tm_type u)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.TypeChecker.Core.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.Metatheory.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Stubs.TypeChecker.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"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": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Syntax.Base.var -> y: Pulse.Syntax.Base.var -> Prims.list Pulse.Syntax.Naming.subst_elt | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.var",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.NT",
"Pulse.Syntax.Pure.tm_var",
"Pulse.Syntax.Base.Mknm",
"Pulse.Syntax.Base.ppname_default",
"Prims.Nil",
"Prims.list"
] | [] | false | false | false | true | false | let renaming x y =
| [NT x (tm_var ({ nm_index = y; nm_ppname = ppname_default }))] | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Greater_Equals_Hat | val op_Greater_Equals_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | let op_Greater_Equals_Hat = gte | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 156,
"start_col": 32,
"start_line": 156
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | Prims.Pure | [] | [] | [
"FStar.UInt128.gte"
] | [] | false | false | false | false | false | let op_Greater_Equals_Hat =
| gte | false |
|
FStar.UInt128.fsti | FStar.UInt128.op_Less_Equals_Hat | val op_Less_Equals_Hat : a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | let op_Less_Equals_Hat = lte | {
"file_name": "ulib/FStar.UInt128.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 60,
"end_line": 157,
"start_col": 32,
"start_line": 157
} | (*
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 | {
"checked_file": "/",
"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"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.BV",
"short_module": "TBV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Math.Lemmas",
"short_module": "Math"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.BitVector",
"short_module": "BV"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "UInt"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt128.t -> b: FStar.UInt128.t -> Prims.Pure Prims.bool | Prims.Pure | [] | [] | [
"FStar.UInt128.lte"
] | [] | false | false | false | false | false | let op_Less_Equals_Hat =
| lte | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.serialize_bounded_der_length_unfold | 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))) | 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)
)
= 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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 36,
"end_line": 743,
"start_col": 0,
"start_line": 717
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_bounded_der_length32_recip | 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) | 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)
= U32.v x | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 9,
"end_line": 970,
"start_col": 0,
"start_line": 965
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.GTot | [
"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"
] | [] | false | false | false | false | 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 | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_seq_flbytes_synth_be_int_eq | 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) | 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)
=
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 | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 40,
"end_line": 874,
"start_col": 0,
"start_line": 853
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | 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 | false |
Pulse.Typing.Metatheory.Base.fsti | Pulse.Typing.Metatheory.Base.nt | val nt : x: Pulse.Syntax.Base.var -> t: Pulse.Syntax.Base.term -> Prims.list Pulse.Syntax.Naming.subst_elt | let nt (x:var) (t:term) = [ NT x t ] | {
"file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 36,
"end_line": 113,
"start_col": 0,
"start_line": 113
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Typing.Metatheory.Base
open Pulse.Syntax
open Pulse.Syntax.Naming
open Pulse.Typing
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
val admit_comp_typing (g:env) (c:comp_st)
: comp_typing_u g c
module RT = FStar.Reflection.Typing
let rt_equiv_typing (#g:_) (#t0 #t1:_) (d:RT.equiv g t0 t1)
(#k:_)
(d1:Ghost.erased (RT.tot_typing g t0 k))
: Ghost.erased (RT.tot_typing g t1 k)
= admit()
val st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c})
(_:st_typing g t c)
: (u:Ghost.erased universe & universe_of g (comp_res c) u)
let inames_of_comp_st (c:comp_st) =
match c with
| C_STAtomic _ _ _ -> comp_inames c
| _ -> tm_emp_inames
let iname_typing (g:env) (c:comp_st) = tot_typing g (inames_of_comp_st c) tm_inames
val st_typing_correctness (#g:env) (#t:st_term) (#c:comp_st)
(d: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) & iname_typing g 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)
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module C = FStar.Stubs.TypeChecker.Core
open FStar.Ghost
val typing_correctness
(#g:R.env)
(#t:R.term)
(#ty:R.typ)
(#eff:_)
(_:erased (RT.typing g t (eff, ty)))
: erased (u:R.universe & RT.typing g ty (C.E_Total, RT.tm_type u))
let renaming x y = [NT x (tm_var {nm_index=y; nm_ppname=ppname_default})]
val tot_typing_renaming1
(g:env) (x:var {None? (lookup g x)}) (tx e ty:term)
(_:tot_typing (push_binding g x ppname_default tx) e ty)
(y:var { None? (lookup g y) /\ x <> y })
: tot_typing (push_binding g y ppname_default tx)
(subst_term e (renaming x y))
(subst_term ty (renaming x y))
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 = RU.magic () | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.TypeChecker.Core.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.Metatheory.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Stubs.TypeChecker.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"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": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Pulse.Syntax.Base.var -> t: Pulse.Syntax.Base.term -> Prims.list Pulse.Syntax.Naming.subst_elt | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.term",
"Prims.Cons",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.NT",
"Prims.Nil",
"Prims.list"
] | [] | false | false | false | true | false | let nt (x: var) (t: term) =
| [NT x t] | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.tag_of_der_length_eq_129 | 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)) | 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))
= 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) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 460,
"start_col": 0,
"start_line": 450
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.log256_eq | val log256_eq
(x: nat)
: Lemma
(requires (x > 0 /\ x < 4294967296))
(ensures (log256 x == log256' x)) | val log256_eq
(x: nat)
: Lemma
(requires (x > 0 /\ x < 4294967296))
(ensures (log256 x == log256' x)) | let log256_eq
x
= log256_unique x (log256' x) | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 920,
"start_col": 0,
"start_line": 918
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: Prims.nat
-> FStar.Pervasives.Lemma (requires x > 0 /\ x < 4294967296)
(ensures LowParse.Spec.DER.log256 x == LowParse.Spec.BoundedInt.log256' x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"LowParse.Spec.DER.log256_unique",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit"
] | [] | true | false | true | false | false | let log256_eq x =
| log256_unique x (log256' x) | false |
Pulse.Typing.Metatheory.Base.fsti | Pulse.Typing.Metatheory.Base.iname_typing | val iname_typing : g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0 | let iname_typing (g:env) (c:comp_st) = tot_typing g (inames_of_comp_st c) tm_inames | {
"file_name": "lib/steel/pulse/Pulse.Typing.Metatheory.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 83,
"end_line": 43,
"start_col": 0,
"start_line": 43
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Typing.Metatheory.Base
open Pulse.Syntax
open Pulse.Syntax.Naming
open Pulse.Typing
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
val admit_comp_typing (g:env) (c:comp_st)
: comp_typing_u g c
module RT = FStar.Reflection.Typing
let rt_equiv_typing (#g:_) (#t0 #t1:_) (d:RT.equiv g t0 t1)
(#k:_)
(d1:Ghost.erased (RT.tot_typing g t0 k))
: Ghost.erased (RT.tot_typing g t1 k)
= admit()
val st_typing_correctness_ctot (#g:env) (#t:st_term) (#c:comp{C_Tot? c})
(_:st_typing g t c)
: (u:Ghost.erased universe & universe_of g (comp_res c) u)
let inames_of_comp_st (c:comp_st) =
match c with
| C_STAtomic _ _ _ -> comp_inames c
| _ -> tm_emp_inames | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Naming.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.TypeChecker.Core.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Typing.Metatheory.Base.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"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": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.tot_typing",
"Pulse.Typing.Metatheory.Base.inames_of_comp_st",
"Pulse.Syntax.Base.tm_inames"
] | [] | false | false | false | true | true | let iname_typing (g: env) (c: comp_st) =
| tot_typing g (inames_of_comp_st c) tm_inames | false |
|
LowParse.Spec.DER.fst | LowParse.Spec.DER.serialize_bounded_der_length32 | 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)) | 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))
= serialize_synth
_
(synth_bounded_der_length32 min max)
(serialize_bounded_der_length min max)
(synth_bounded_der_length32_recip min max)
() | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 981,
"start_col": 0,
"start_line": 972
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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)
() | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.parse_bounded_der_length32 | 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)) | 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))
= parse_bounded_der_length min max `parse_synth` synth_bounded_der_length32 min max | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 83,
"end_line": 933,
"start_col": 0,
"start_line": 929
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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) | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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) | false |
LowParse.Spec.DER.fst | LowParse.Spec.DER.synth_der_length_greater_recip | 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))}) | 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)) } )
= assert_norm (der_length_max == pow2 (8 * 126) - 1);
Math.pow2_lt_recip (8 * (log256 y - 1)) (8 * 126);
y | {
"file_name": "src/lowparse/LowParse.Spec.DER.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 488,
"start_col": 0,
"start_line": 481
} | 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))
= () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))} | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |